Reputation: 111
How to parse an object like this with jQuery or javascript:
Object { 4: Array[1], 5: Array[1] } //arrSrok
$.each(arrSrok, function(srokID, arrKhum) {
console.log(arrKhum); //runs only once, and I got srokID = 4, arrKhum empty
});
It seems that arrKhum cannot be assigned with an array. What do I miss?
Though I can parse an object with the following format successfully
Object { 1: Object, 2: Object }
Upvotes: 2
Views: 288
Reputation: 8168
This is what I tried and it seems to be working correctly
var someObject = { 4: [3,4], 5: [1,2] };
EDIT: If you want to loop through array, you can use $.isArray
provided by JQuery
$.each(someObject, function(key, value) {
if($.isArray(value)){
$.each(value,function(key1,value1){
console.log(value1);
});
}
});
Here is the Link
Upvotes: 3