Javascript Array insert(p_index, newObj)

Description

Javascript Array insert(p_index, newObj)


Array.prototype.insert = function(p_index, newObj){
 var l = this.length;
 var precObj = null;
 for(var i=0; i<l; i++){
  if(precObj != null){
   var obj = precObj;
   precObj = this[i];/*from w  w  w.  j a  v  a2s. c  o m*/
   this[i] = obj;
  }else if(i == p_index){
   precObj = this[i];
   this[i] = newObj;
  }
 }
 if(precObj != null){
  this.push(precObj);
 }else{
  this.push(newObj);
 }
};



PreviousNext

Related