我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