Javascript Array moveDown(element, offset)

Description

Javascript Array moveDown(element, offset)


Array.prototype.moveDown = function(element, offset) 
{
    var index = this.indexOf(element); 
    var newPos = index + (offset || 1);
    /*from  w w w .  ja  v a2  s .c  o m*/
    if(index === -1) { throw new Error("Element not found in array"); }
    
    if(newPos >= this.length) { newPos = this.length; }
    
    this.splice(index, 1);
    this.splice(newPos,0,element);
};



PreviousNext

Related