我JSON對象的數組,我喜歡這個屬性添加到遠程數據
var arr = [];
$.getJSON('http://localhost:port/api/blah/blah', function(jsonPayload) {
console.log('Getting JSON...');
// Do stuff with JSON data here, or call a function here and
// pass the data to it as an argument
arr = jsonPayload;
console.log('arr IS SET!');
functionCall();
//printArr(arr);
});
我的哪個陣列,編曲,有一堆看起來像這樣
JSON對象獲得獲得JSON對象{
"id": 123,
"name": "Joe Schmo",
"blah": "blah",
.
.
.
}
Anddd我嘗試一個新的屬性添加到這些對象的每一個像這樣
for (var i = 0; i < arr.lenth ; i++)
{
var curr = arr[i];
curr.newProp= 0;
}//end for loop adding newProp property
但是當我用JSON對象查看完成的數組時,我發現我的newProp 不是添加到JSON對象。
這是爲什麼,你能幫我嗎?
順便說一句:爲什麼你定義'curr'?它不用於你的代碼 – hindmost 2014-10-06 17:51:38
編輯:這是一個錯字,當我發佈的問題,我現在修復。感謝您的注意。 – 2014-10-06 17:53:24
你有長度而不是長度 – juvian 2014-10-06 17:54:21