編輯:
對不起,之前貼錯響應。看看使用圖書館,使這個很容易_countBy
var els = [];
els.push({"ID":13,"PO_ID":1,"PO_NM":"Chemical","POINT_NAME":"TES HFJGH KH"});
els.push({"ID":13,"PO_ID":1,"PO_NM":"Chemical","POINT_NAME":"KRUTIKA PATEL"});
els.push({"ID":14,"PO_ID":2,"PO_NM":"Electrical","POINT_NAME":"SDA SHFKJ KJSJDHF KJSHDKJ JK"});
els.push({"ID":14,"PO_ID":2,"PO_NM":"Electrical","POINT_NAME":"KJHG S DJKFH JSKJSDKJFH KJ"});
els.push({"ID":15,"PO_ID":3,"PO_NM":"Water","POINT_NAME":"ERTERSHFKJ HNSJFH KJS"});
var cnts = _.countBy(els,'PO_NM');
alert(JSON.stringify(cnts));
console.log(cnts);
https://jsfiddle.net/HappyiPhone/370mL2v2/4/
以前的答案:
看的文檔.filter
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
var els = [];
els.push({ID: '13', 'POINT_NAME': 'TEST', PO_ID: '1', 'PO_NM': 'Chemical'});
els.push({ID: '14', 'POINT_NAME': 'TEST', PO_ID: '2', 'PO_NM': 'Electrical'});
els.push({ID: '15', 'POINT_NAME': 'TEST', PO_ID: '3', 'PO_NM': 'Chemical'});
els.push({ID: '16', 'POINT_NAME': 'TEST', PO_ID: '4', 'PO_NM': 'Electrical'});
var els2 = els.filter(function(word){
return word.PO_NM == 'Chemical';
})
console.log(els2);
$(els2).each(function(i){
alert(els2[i].PO_NM + ' ' + els2[i].ID);
})
https://jsfiddle.net/HappyiPhone/370mL2v2/
如果你鍵入代碼的數組內容這將是真正有用的,不能INA一個圖像,否則有人需要爲你輸入。 – ProgrammerV5
爲您的元素添加了示例。希望能幫助到你! – ProgrammerV5
請顯示你的嘗試。 Stackoverflow不是免費的代碼寫入服務。這裏的目標是幫助你解決**你的代碼**。你可以使用任何數量的不同的循環方法來做你在問什麼 – charlietfl