Javascript Array add( item )

Description

Javascript Array add( item )

Array.prototype.add = function ( item ) {
 var index = this.length;
 this[ index ] = item;/*from  w  w  w.  ja  va  2  s  . c om*/
 return index;
};

Array add(c)


Array.prototype.add = function(c){
  var me = this;// w  ww .j av a 2  s .  co  m
  me.forEach(function(v, k){
    me[k] = v + c;
  });
};
var arr = [1, 2, 3];
arr.add(2);
console.log(arr);

Array add(e)


Array.prototype.add = function (e) {
    this.push(e);//from  w w w  . ja  v a 2s .c  o  m
};

Array add(el)


Array.prototype.add = function (el) {
    var index = this.indexOf(el);
    if (index == -1) {
        this.push(el);//from  ww  w .j  a  v a  2  s  . c  om
    }
};

Array add(item)


/**/*from   w  w w . j a  va 2s .c  o  m*/
 * 
 */
var SEP = ',';

Array.prototype.add = function(item) {
    for ( var i = 0; i < this.length; i++) {
        if (this[i] === item) {
            return this;
        }
    }
    this[this.length] = item;
    return this;
}

Array add(value)


Array.prototype.add = function(value) {
    this[this.length] = value;//from   w w w  . j ava2  s.c  o  m
};



PreviousNext

Related