如何将对象分配到循环中的数组中?
到目前为止我的进展
item = [];
$.each(result, function(){
//loop and assign array into an array
//result is an object
//result.a
//result.b
});
预期的最终结果
item = [
{'a': a},
{'b': b },
.....
]
答案 0 :(得分:1)
var item = [];
$.each(result, function(key, value) {
var newobj = {};
newobj[key] = value;
item.push(newobj);
}