Nodejs Utililty Methods Array Move Down

List of utility methods to do Array Move Down

Description

The list of methods to do Array Move Down are organized into topic(s).

Method

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);
};
...
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);
moveDown(value, by)
Array.prototype.moveDown = function(value, by) {
    var index = this.indexOf(value),
        newPos = index + (by || 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,value);
...
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);
};