I have a complex nested array of objects like this for which I have to return a new Array(filter) based on attributeScore > 90. How will I accomplish this using the javascript .filter or the lodash _.find() or _.some function ?
trucks:[
{wheels:[
{name:"xyz",
mechanics: [
{engine:'50cc',
attributeScore:100},
{....} ,{...}
]
},
{name:"gcd",
mechanics: [
{engine:'80cc',
attributeScore:90},
{....} ,{...}
]
},
,{...}
]}
,{...}
]
I tried a filter like this
const fil = trucks.filter(function(item) {
return item.wheels.some(function(tag) {
return tag.mechanics.some(function(ques){
return ques.attributeScore <= 25;
});
});
});
but it returns an empty array . My expected return array type should be
trucks:[
{wheels:[
{name:"xyz",
mechanics: [
{engine:'50cc',
attributeScore:100},
{....} ,{...}
]
},
,{...}
]}
]
Any help appreciated!!