0

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 {}
  1. If [arr] is ultimately an object, wouldn't this refer to [arr]?
  2. At the end of the day, I just wanted to get arr[0] via this
isherwood
  • 58,414
  • 16
  • 114
  • 157

0 Answers0