0
我想獲取數組內對象的值,即數組中對象的值。
jQuery的
// aim: to alert value of 'm1' for each object (represented as a day)
myArray = [{"monday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]},{"tuesday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]},{"wednesday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]},{"thursday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]},{"friday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]},{"saturday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]},{"sunday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]}]
$.each(myArray, function(k,v) {
$.each(k, function(k2,v2) {
alert(v2.m1)
});
});
的jsfiddle
http://jsfiddle.net/rwone/py8Jz/3/
嵌套循環也許? – Daniel