Javascript Array moveDown(value, by)

Description

Javascript Array moveDown(value, by)

Array.prototype.moveDown = function(value, by) {
 var index = this.indexOf(value);
 if (index === -1) {
  throw new Error('Item not found');
 }
 var newPos = index + (pos || 1);
 if (newPos >= this.length) {
  newPos = this.length;/*from   ww w .j  ava 2s.  com*/
 }

 this.splice(index, 1);
 this.splice(newPos, 0, value);
}



PreviousNext

Related