I would like to write my own function for every array and I'm using the prototype
keyword.
The problem is that when I created the following script:
Array.prototype.test = () => {console.log('length: ',this.length)};
const result = [1,2,3].test();
If I run it in the console of chrome I get the following result:
length: 0
If I run it on my local machine with node script.js
I get the following result:
length: undefined
Why is this.length
different and why it doesn't reflect the length of the array I'm calling the function on?