Published
- 1 min read
js get array item by property
The solution for this is noted below
js get array item by property
Solution
const jsObjects = [
{ id: 1, displayName: 'First' },
{ id: 2, displayName: 'Second' },
{ id: 3, displayName: 'Third' },
{ id: 4, displayName: 'Fourth' }
]
// You can use the arrow function expression:
var result = jsObjects.find((obj) => {
// Returns the object where
// the given property has some value
return obj.id === 1
})
console.log(result)
// Output: {id: 1, displayName: "First"}
Try other methods by searching on the site. That is if this doesn’t work