Reputation: 16
I have some JSON file:
"productsAtributesMaping":[
{
"model":"first",
"params":["0", "1", "2"]
},
{
"model":"second",
"params":["0", "1", "2", "3", "4"]
}
]
How to output a params of each object with loop?
Upvotes: 0
Views: 57
Reputation: 337570
You can use each()
like this:
$.each(data.productsAtributesMaping, function(i, val) {
$.each(val.params, function(x, param) {
console.log(param);
});
});
Upvotes: 1
Reputation: 7269
Use parseJSON
and for..in
loop:
// fill in `jsonData` variable
var obj = jQuery.parseJSON(jsonData);
for(var i in obj) {
var item = obj[i];
console.log(item.model);
console.log(item.params);
}
Upvotes: 0