Javascript Array pushAll(items)

Description

Javascript Array pushAll(items)


Array.prototype.pushAll = function (items) {

    // items must be an array
    if (! Array.isArray (items)) {
        throw new TypeError("Argument must be an array");
    }/*  w  w w .ja v a2s.c  o  m*/

    return this.push(...items);
};

Javascript Array pushAll(items)

//access the global scope

// module code without exports or imports
Array.prototype.pushAll = function (items) {
// items must be an array
    if (!Array.isArray(items)) {
        throw new TypeError("Argument must be an array.");
    }/*from w  w w . j  av a 2  s .c  om*/
// use built-in push() and spread operator
    return this.push(...items);
};

Javascript Array pushAll(items)

// module code without exports or imports
Array.prototype.pushAll = function(items) {

    // items must be an array
    if (!Array.isArray(items)) {
        throw new TypeError("Argument must be an array.");
    }//  w w w  .  j  a  v  a 2s  .c om

    // use built-in push() and spread operator
    return this.push(...items);
};



PreviousNext

Related