Answer the question
In order to leave comments, you need to log in
JSON data filter?
I have a JSON array:
var json = [{
"variation_id": 618,
"attributes": {
"attribute_pa_color": "navy",
"attribute_pa_size": "l"
},
"sku": "618"
}, {
"variation_id": 619,
"attributes": {
"attribute_pa_color": "gray",
"attribute_pa_size": "l"
},
"sku": "619"
},
{
"variation_id": 620,
"attributes": {
"attribute_pa_color": "navy",
"attribute_pa_size": "s"
},
"sku": "620"
}, {
"variation_id": 621,
"attributes": {
"attribute_pa_color": "gray",
"attribute_pa_size": "s"
},
"sku": "621"
}];
{
"variation_id": 618,
"attributes": {
"attribute_pa_color": "navy",
"attribute_pa_size": "l"
},
"sku": "618"
},{
"variation_id": 620,
"attributes": {
"attribute_pa_color": "navy",
"attribute_pa_size": "s"
},
"sku": "620"
}
Answer the question
In order to leave comments, you need to log in
var newJson = json.filter(function(e){
return e.attributes.attribute_pa_color == "navy";
});
Sequentially pass through the array, get the value of the desired property of the object, compare.
Which of these are difficult for you?
It has already been told here:
stackoverflow.com/questions/18504285/how-to-filter...
And in general, there are a lot of things on Google for this query: json filter by attributes
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question