1

My ask is quite simple here, i have a lightning component where i have an attribute of type Array of Account (Account[]). This array already has a list of Account records. At a certain event (on click of a button), i need to find the account record from the array, corresponding to a record id that i have.

I tried to find a JS method to do so, but couldn’t. Any help here would be appreciated.

Component: <aura:attribute name="studentsList" type="Account[]" default="{}"/>

1 Answer 1

1

Array.prototype.find() is your friend =)

you simply need to match against your record id:

<Array>.find( element => element.id === <yourRecordId>)

this will return the first element matching element.id === <yourRecordId>

1
  • Hi, thanks for replying. This does look like the one, although i just tried to run the following code but it shows 'undefined' in the alert, not sure if i am missing something: var contextStudent = students.find(element => element.id === accId); alert(contextStudent); Jun 9, 2021 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.