[JS] Find an object in an array
This sample shows how to find an object with key, value in an array.
find() method will stop loop when the condition is true.
If the condition is not true then return undefined
.
let users = [
{id: 1, name: "John"},
{id: 2, name: "Pete"},
{id: 3, name: "Mary"}
];
let user = users.find(item => item.id == 1);
console.log(user);
MDN Web Docs
Comments