0

I just stumble with this line of code and I'm struggling to understand what it means:

const selected = find(this.list, {
          [this.keyName]: control[0]
            ? control[0][this.keyName]
            : control.value
        });

The part that confuse me is [this.keyName]: control[0] ? control[0][this.keyName] : control.value ... what exactly means [this.keyName]: control[0] as a condition ?

Manuel Navarro
  • 1,789
  • 2
  • 16
  • 18
  • That simply means you are using the string value of `this.keyName` as the key in the object. So, if `this.keyName` is `"foo"`, then your object will look like `{ 'foo' : ... }` – Terry Dec 29 '20 at 15:03
  • https://stackoverflow.com/a/31024830/712558 – danronmoon Dec 29 '20 at 15:03
  • Only `control[0]` is part of the condition. `[this.keyName]:` is the property name part of the property definition in the object literal. – Felix Kling Dec 29 '20 at 15:04
  • OK, now I get it, the second argument of the find method is defining the object I'm looking for in the array (first parameter)... so, as you all explain, is just the key of the object, and the condition is what comes after and will determine the value for that key. Sorry sometimes I get confused with the syntax. For some reason my brain was looking for a function in the second argument and that's why I wasn't understanding... should I delete this question? – Manuel Navarro Dec 29 '20 at 17:24

0 Answers0