循环访问jQuery 中 JSON 的键/值对

1.jQuery.each()
该方法的定义为jQuery.each( collection, callback(indexInArray, valueOfElement) )
jQuery网站上有下面的例子:
var map = { 
  'flammable': 'inflammable', 
  'duh': 'no duh' 
}; 
$.each(map, function(key, value) { 
  alert(key + ': ' + value); 
});


结果为:
flammable: inflammable
duh: no duh
2.用for循环
 for (var prop in obj) {
      alert(prop + " is " + obj[prop]);
   }

你可能感兴趣的:(jquery,each,for)