Reputation: 269
How to assign object into an array within a loop?
My progress so far
item = [];
$.each(result, function(){
//loop and assign array into an array
//result is an object
//result.a
//result.b
});
Expected final result
item = [
{'a': a},
{'b': b },
.....
]
Upvotes: 0
Views: 64
Reputation: 780779
var item = [];
$.each(result, function(key, value) {
var newobj = {};
newobj[key] = value;
item.push(newobj);
}
Upvotes: 1