I am trying to get some particular property with value from an array object.But it is not working.How to resolve this issue?
var arr1 = [
{
name: 'john',
team: [12, 23, 34],
sid: 1023,
options:{boolean:true}
},
{
name: 'john',
team: [152, 233, 354],
sid: 1024,
options:{boolean:true}
},
{
name: 'john',
team: [152, 273, 314],
sid: 1025,
options:{boolean:true}
},
];
const filteredResult = arr1.find((e) => e.!sid && e.!options);
console.log(filteredResult);
filteredResult should be like
[
{
name: 'john',
team: [12, 23, 34]
},
{
name: 'john',
team: [152, 233, 354]
},
{
name: 'john',
team: [152, 273, 314]
}
];
3
Answers
You can destructure only the properties you want to be returned.
Or, with a dynamic array of properties to extract:
array.map()
should do it. Just return the specific properties that you wantarr1.find()
will only return the first matching element. Use arrayfilter
instead if you want to get all the matching elements.