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]
}
];
Demo: https://stackblitz.com/edit/js-73yhgm?file=index.js
>Solution :
array.map() should do it. Just return the specific properties that you want
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 result = arr1.map(x => ({
name: x.name,
team: x.team
}))
console.log(result)