Nodejs Array Insert insert(index, item)

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

Method Source Code

// var nums = ["one", "two", "four"];
// nums.insert(2, "three"); //
// nums --->>>> ["one", "two", "three", "four"]
Array.prototype.insert = function (index, item) {
   this.splice(index, 0, item);//from w w  w.ja v  a2 s.  c  o m
}

Related

  1. insert(idx, item)
    Array.prototype.insert = function(idx, item) {
      this.splice(idx, 0, item);
    };
    
  2. insert(index , item)
    Array.prototype.insert = function(index , item){
        this.splice(index, 0, item);
    };
    
  3. insert(index)
    Array.prototype.insert = function(index) {
        this.splice.apply(this, [index, 0].concat(
            Array.prototype.slice.call(arguments, 1)));
        return this;
    };
    
  4. insert(index)
    Array.prototype.insert = function(index) {
        function isArray(instance) {
            return Object.prototype.toString.call(instance) !== '[object Array]';
        if (!isArray(this)) {
            throw new TypeError("`this` must be Array, not " + typeof this);
        if (typeof index !== 'number') {
            throw new TypeError("arguments[0] must be number (index to insert at), not " + typeof arguments[0]);
    ...
    
  5. insert(index, item)
    Array.prototype.insert = function (index, item) {
      if (index)
        this.splice(index, 0, item);
      else
        this.push(item);
    };
    
  6. insert(index, item)
    Array.prototype.insert = function(index, item) {
      this.splice(index, 0, item);
      return this;
    };
    
  7. 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];
      });
    
  8. 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);
    ...
    
  9. 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) {
    ...