Nodejs Array Remove by Index removeAtIndex(index)

Here you can find the source of removeAtIndex(index)

Method Source Code

// A stack and a queue are similar in design, i.e. both can be made from a linked list, but they differ in the way 
// items are accessed by default. A stack gives you the items it contains via last in, first out. A queue gives 
// the items it contains via first in, first out.

// You would a stack to process an execution chain, where the last function on the stack is executed first. You 
// would use a queue when you are processing requests or jobs, where the first job intot he queue is the first 
// job to be processed. 

Array.prototype.removeAtIndex = function(index){
  if (typeof(index) !== "number") {
    throw new Error("Input argument was not a number");
  } else if (index >= this.length || index < 0) {
    throw new Error("Input index is out of range");
  } else {// ww w .j  a va 2  s  .co  m
    var index = Math.floor(index);
    this.splice(index, 1);
    return this;
  }
};

Array.prototype.last = function(){
  return this[this.length - 1];
};

Array.prototype.first = function(){
  return this[0];
};

Related

  1. removeAt(index)
    Array.prototype.removeAt=function(index){
      this.splice(index,1);
    
  2. removeAt(index)
    Array.prototype.removeAt = function(index) {
        if (index > this.length - 1 || index < 0) {
            throw new Error("Index out of range");
        this.splice(index, 1);
    };
    
  3. removeAt(position)
    Array.prototype.removeAt = function(position){
        this.splice(position,1);
    };
    
  4. removeAtIndex(elementAt)
    Array.prototype.removeAtIndex = function(elementAt) {
      return this[elementAt - 1];
    };
    
  5. removeAtIndex(index)
    Array.prototype.removeAtIndex = function(index) {
      this.splice(index, 1);
    };
    
  6. removeByIndex(i)
    Array.prototype.removeByIndex = function(i) {
       return this.splice(idx, 1);
    
  7. removeByIndex(index)
    Array.prototype.removeByIndex = function (index) {
        var tempList = Array();
        for (var i = 0, a = 0; i < this.length; i++) {
            if (i != index) {
                tempList[a] = this[i];
                a++;
        this.setArray(tempList);
    ...
    
  8. removeByIndex(index)
    Array.prototype.removeByIndex = function(index){
      var i=0,n=0;
      for(i=0;i<this.length;i++){
        if(this[i]!=this[index]){
          this[n++]=this[i];
      if(n<i){
        this.length = n;
    ...
    
  9. removeByIndex(index)
    Array.prototype.removeByIndex = function(index){
      var i=0,n=0;
      var arrSize = this.length;
      for(i=0;i<arrSize;i++){
        if(this[i] != this[index]){
          this[n++]=this[i];
      if(n<i){
    ...