有这么一个JSON数组,需求是只需要输出每个数组里面的某个值,不需要全部输出来。
var data = [{ "MachineID":"171914", "Cost":"13,642.41", "Currency":"PHP"},{ "MachineID":"172233", "Cost":"1,367.73", "Currency":"PHP"},{ "MachineID":"41116", "Cost":"2,608.20", "Currency":"PHP"},{ "MachineID":"178077", "Cost":"1,517.04", "Currency":"PHP"},{ "MachineID":"176430", "Cost":"20,876.72", "Currency":"PHP"}]
假设我们输出全部的值,则按照前面一篇文章说过的,只需要遍历两次就可以输出,如下:
var _html = '';$.each(data,function(index,obj){_html +=''+(index+1) +'
';$.each(obj,function(key,value){_html += '
';})$("#content").append(_html);- '+key+" : "+value+'
';})_html +='
基于本文只需要每个数组的第一个值,可以使用前文说过的的最快第四种
var output = [];$.each(data, function(key,value){output.push('
或者是前文说过的第五种
var ul = $('ul');$.each(data,function(i,obj) {$('