This is my JSON object array which contains nested objects :
var obj= [
{
"ASIN":"BCXXXXX1",
"VariationAttributes":[
{
"Name":"hand_orientation",
"Value":"Left Hand"
},
{
"Name":"shaft_material_type",
"Value":"KBS Max 90 Steel"
}
]
},
{
"ASIN":"BCXXXXX2",
"VariationAttributes":[
{
"Name":"hand_orientation",
"Value":"Right Hand"
},
{
"Name":"shaft_material_type",
"Value":"KBS Max 90 Steel"
}
]
}
]
var curState=[
{
"Name":"hand_orientation",
"Value":"Left Hand"
},
{
"Name":"shaft_material_type",
"Value":"KBS Max 90 Steel"
}
]
Now I want to filter out items that have variationAattributes that match curState.
var result = obj.map(m=>m.VariationAttributes).filter(search, curState);
function search(item){
return Object.keys(this).some((key) => item[key] === this[key]);
}
The result is blank. You can play with the code at https://playcode.io./518049
filterdefinition: developer.mozilla.org/fr/docs/Web/JavaScript/Reference/…