I have an object, which contains 2 name parameters – see the example below. I understand that to reach the data I need to loop through the object, but I feel this is too annoying. Is there a better way to get the data in simple way?
var obj = {[[[{name:'one'},{name:'two'}]]]};
$.each(obj,function(i,val){
var first = [] // i will get first time
$.each(first, function(i, val){
var second = [] //i will get second time and third later fourth // like so?
})
})
Does this mean that I should loop the each function four times to get the name values? If so which is the right way to get that? Is there any way to use the same function to get the data?
Your
objis invalid.So, try something this:
DEMO
Another one (for any level of array)
DEMO
Note
{}always contains data withkey : valuepair. So, in your case{ [ .. ] }is invalid format of object. some correct formats of object may be:Suggestion
If you’ve option then change the format of your
objlike below:And try following code simply: