Answers for "javascript array-like object"

0

javascript array-like object

function Arraylike(... args) {
    this.xarg = args;
    this.slice = function(num) {
        return new Arraylike(...this.xarg.slice(num));
    };
    this.splice = function(... args) {
        console.error("Splice is not implemented for now.");
    };
    this.toArray = function() {
        return this.xarg;
    };
    this.length = this.xarg.length;
    for(let i = 0; i < this.xarg.length; i++) {
        this[i] = this.xarg[i];
    }
}



Array.prototype.toArraylike = function() {
    return new Arraylike(...this);
};


let yourobject = new Arraylike("whatever", "goes", "here");
Posted by: Guest on April-29-2021

Code answers related to "javascript array-like object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language