-1

Let's say I have an array of objects that looks like this:

  var obj1 = [{
          fullName ='Jon Doe',
          Name     ='Jon',
          age      ='17',
       },
       {
        fullName     ='Bob Smith',
        Name     ='Bob',
        age     ='34',
       }
   ]

If I have a var CustomerName = 'Jon', how can I possibly retrieve the age for Jon

  var cName = obj1.filter(function(item)){
      return item['age'] //?? Where item['name'] == customerName
  }

I am a little lost, am i on the right path? THanks.

Shrimp2022
  • 51
  • 8

1 Answers1

0

You're looking for something like this:

const filtered = (item) => {
  item.name === customerName
}

return obj1.filter(filtered).forEach((obj) => obj.age)
Sean
  • 1,368
  • 2
  • 9
  • 21
  • This is a clear [duplicate](https://stackoverflow.com/a/35398031/13762301) with more thorough explanation, flag instead. – pilchard Feb 18 '22 at 22:21