-
qq_花开花谢_0
摘自jQuery文档:var arr = [ "one", "two", "three", "four", "five" ];var obj = { one:1, two:2, three:3, four:4, five:5 };jQuery.each(arr, function() {
$("#" + this).text("My id is " + this + ".");
return (this != "four"); // will stop running to skip "five"});jQuery.each(obj, function(i, val) {
$("#" + i).append(document.createTextNode(" - " + val));});
-
一只甜甜圈
var arr = [ {"id":"10", "class": "child-of-9"}, {"id":"11", "classd": "child-of-10"}];for (var i = 0; i < arr.length; i++){ var obj = arr[i]; for (var key in obj){ var attrName = key; var attrValue = obj[key]; }}var arr = [ {"id":"10", "class": "child-of-9"}, {"id":"11", "class": "child-of-10"}]; for (var i = 0; i < arr.length; i++){ document.write("<br><br>array index: " + i); var obj = arr[i]; for (var key in obj){ var value = obj[key]; document.write("<br> - " + key + ": " + value); }}注意:对于简单对象来说,for-in方法是很酷的。与DOM对象一起使用并不是很明智。
-
守候你守候我
使用前程:<html><body><script type="text/javascript">var mycars = [{name:'Susita'}, {name:'BMW'}];for (i in mycars){
document.write(mycars[i].name + "<br />");}</script></body></html>将导致:SusitaBMW