I have custom array-like object, with all the array methods, which acts as an array, but Object.prototype.toString.call(myArrayLikeObj) returns [object Object] not [object Array]
How to prepare my object to return [object Array]?
Can I see somewhere Object.toString source code?
>Solution :
Symbol.toStringTag is the well-known name of the "tag" you want:
YourCustomArrayPrototype[Symbol.toStringTag] = () => 'Array'; // Sure, why not?
That said, if you extend Array you will get this for free:
class MyCustomArray extends Array {}
console.log(
Object.prototype.toString.call(new MyCustomArray(3))
); // Logs [object Array]