Nodejs Array Insert insert(index, item)

Here you can find the source of insert(index, item)

Method Source Code

/*//from ww  w.  ja  v  a 2s. co  m
*   Custom functions added to array object
*   in order for easier manipulations on task's 
*   children and registering keys for events.
*/

/*
*   Used for removing one of the children 
*   of the parent task.
*/
Array.prototype.insert = function (index, item) {
   this.splice(index, 0, item);
};
/*
*   Used for key registering in the tree event keys
*/
Array.prototype.registerKeys = function(keys){
   for(var i=0;i< keys.length;i++){
      this.push(keys[i]);
   }
};
/*
*   Checks whether the array contains the item
*/
Array.prototype.contains = function(item){
   for(var i=0;i< this.length;i++){
      if(item == this[i]){
         return true;
      }
   }
   return false;
};
/*
*   Checks whether the html element exists
*/
function isDOMElementExist(element){
   if($(element).length >0){
      return true;
   }
   return false;
};

Related

  1. insert(index, item)
    Array.prototype.insert = function (index, item) {
      this.splice(index, 0, item);
    
  2. insert(index, item)
    Array.prototype.insert = function(index, item) {
      this.splice(index, 0, item);
      return this;
    };
    
  3. insert(index, item)
    Array.prototype.insert = function(index, item) {
      this.splice(index, 0, item);
      return this;
    if (Function.prototype.name === undefined){
      Object.defineProperty(Function.prototype,'name',{
        get: function(){
          return /function ([^(]*)/.exec( this+"" )[1];
      });
    
  4. insert(index, item)
    Array.prototype.insert = function(index, item) {
      var args = this.slice.call(arguments),
          index = args.shift();
      args = [index,0].concat(args);
      this.splice.apply(this, args);
      return this;
    var result = [1,2,3,4,7,8,9,10].insert(4,5,6);
    console.log(result);
    ...
    
  5. insert(index, item)
    Array.prototype.insert = function (index, item) {
      this.splice(index, 0, item);
    };
    function insertionSort (array) {
      var sorted = [];
      function backItUp(obj) {
        if(!sorted.length) return sorted.push(obj);
        for(var j=sorted.length-1; j>=0; j--) {
          if(obj.value >= sorted[j].value) {
    ...
    
  6. insert(index, item)
    Array.prototype.insert = function(index, item) {
      index = Math.min(index, this.length);
      arguments.length > 1
        && this.splice.apply(this, [index, 0].concat([].pop.call(arguments)))
        && this.insert.apply(this, arguments);
      return this;
    
  7. insert(index, value)
    Array.prototype.insert = function(index, value)
      if(index >= 0)
        var a = this.slice(), b = a.splice(index);
        a[index] = value;
        return a.concat(b);
    };
    ...
    
  8. insert(index, value)
    Array.prototype.insert = function (index, value) {
        this.splice(index, 0, value);
    };
    
  9. insert(object)
    Array.prototype.insert = function(object) {
      this[this.length] = object;
      return this;