0

Here is a simple example.

let obj = {
    arr: [11, 22, 33]
}
let first = obj[0]; // just want to get the first value of obj.arr;

Is there any way to intercept the method that [] is actually executing, so that I can return the value I want?

  • 2
    Does this answer your question? [How would you overload the \[\] operator in javascript](https://stackoverflow.com/questions/1711357/how-would-you-overload-the-operator-in-javascript) - i.e., write a function that'll do it instead, or use a proxy if you have ES6 support. – Nick is tired Jun 22 '21 at 14:49
  • If you want to get the first value, have you tried obj.arr[0] ? – DirtyHands Jun 22 '21 at 14:56

0 Answers0