How to find value in an array of objects with JavaScript

1 Answer

0 votes
const users = [
  {
    name:'Spock', id:12343
  },
  {
    name:'Nyota', id:84932
  },
  {
    name:'Scotty', id:90828
  },
  {
    name:'Hikaru', id:73104
  }
]


console.log(users.find((user)=>user.name === 'Scotty'))


 
 
/*
run:
 
{
name: "Scotty" ,
id: 90828
} 
 
*/


 



answered May 19, 2021 by avibootz
edited May 19, 2021 by avibootz
...