我有這個陣列創造價值形式arryay Jquery?
var activeId = 1;
var getAll = [{
"id": "1",
"name": "John",
"position": "CEo",
"office": "NY",
"active": "Yes"
}, {
"id": "2",
"name": "John",
"position": "CEo",
"office": "NY",
"active": "Yes"
}]
我需要的是與activeId = 1來獲得唯一成員,並且不是創建新的變種,我可以提醒?
嘗試過這樣的事情,但我沒有運氣?
$.each(getAll, function(_, val) {
if (val.id == activeId) {
name = val.name;
position = val.position;
office = val.office;
}
});
alert(position);
的警報沒有顯示。 – 2014-09-30 12:09:35
它顯示,但在所有名稱,位置,辦公室我得到了相同的結果? – Schneider 2014-09-30 12:11:12