Nodejs Array Move Down moveDown(value, by)

Here you can find the source of moveDown(value, by)

Method Source Code

Array.prototype.moveDown = function(value, by) {
    var index = this.indexOf(value),
        newPos = index + (by || 1);/* w w  w  . jav  a  2 s. co  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,value);
    
    return newPos;
};

Related

  1. moveDown(element, offset)
    Array.prototype.moveDown = function(element, offset) 
        var index = this.indexOf(element); 
        var newPos = index + (offset || 1);
        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);
    };
    ...
    
  2. 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;
      this.splice(index, 1);
      this.splice(newPos, 0, value);
    
  3. moveElement(index, delta)
    Array.prototype.moveElement = function (index, delta) {
        var index2, temp_item;
        if (index < 0 || index >= this.length) {
            return false;
        index2 = index + delta;
        if (index2 < 0 || index2 >= this.length || index2 == index) {
            return false;
        temp_item = this[index2];
        this[index2] = this[index];
        this[index] = temp_item;
        return true;
    };
    Array.prototype.getPageData = function(data, pageSize, currentPageNo)
        var start = currentPageNo * pageSize,
            end = (currentPageNo * pageSize + pageSize) > data.length
                    ? data.length
                    : (pageSize * pageSize + pageSize);
        return data.slice(start, end);
    };