javascript array like object

Solutions on MaxInterview for javascript array like object by the best coders in the world

showing results for - "javascript array like object"
Naya
11 Aug 2017
1function Arraylike(... args) {
2    this.xarg = args;
3    this.slice = function(num) {
4        return new Arraylike(...this.xarg.slice(num));
5    };
6    this.splice = function(... args) {
7        console.error("Splice is not implemented for now.");
8    };
9    this.toArray = function() {
10        return this.xarg;
11    };
12    this.length = this.xarg.length;
13    for(let i = 0; i < this.xarg.length; i++) {
14        this[i] = this.xarg[i];
15    }
16}
17
18
19
20Array.prototype.toArraylike = function() {
21    return new Arraylike(...this);
22};
23
24
25let yourobject = new Arraylike("whatever", "goes", "here");