I had this wild thought of adding a method to an array - i just don't know if this is possible. I'll forever be indebted to some knowledge you might share :)
const arr = [1,2,3,4];
arr.hello = () => {return this};
console.log(arr['hello']()); //outputs an empty object {}
- If
[arr]
is ultimately an object, wouldn'tthis
refer to[arr]
? - At the end of the day, I just wanted to get
arr[0]
viathis