Nelson Tan Nelson Tan - 4 months ago 9
jQuery Question

Passing array to jquery arguments

I want the result of my alert become

a[one:1]..b[four:4]..
here is my code

var myObject = {
a: {
one: 1,
two: 2,
three: 3
},
b: {
four: 4,
five: 5,
six: 6
}
};
$.each(myObject, function(a, b) {
alert(a + b);
})

Answer

Try like this

$.each(myObject, function(a, b) {
  $.each(b, function(c, d) {
    alert(a + "["+c+":"+d+"]" );
  })
})

DEMO