Skip to content
Advertisement

Looping through an array of objects and filter using a key

I have a nested array of objects as below

JavaScript

I would like to loop through the array and get the address object corresponding to the firstName ‘Max’.

I can use this data to generate links and their sublinks (on clicking the links)

I have attempted the following

JavaScript

Then

JavaScript

But it returns undefined. How can solve it?

Advertisement

Answer

You should look up array find().

It would look something like this:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement