I need to create a new object iterating over an array of objects which initially looks like this:
startObj = [{'prop': true}, {'prop': false}];
I would like the result to be:
endObj = {0: true, 1: false}
I was thinking to use $.each but then I don't know how to proceed from here. Any hints?
$.each([{'prop': true}, {'prop': false}], function (i, o) {
var newObj;
// the new object should look like this
// newObj = {0: true, 1: false}
});
0,1etc, however this looks a lot like an array - and most answers give you back an array not an object. What is it you actually want back?.eachto iterate over it. And why not? If you're using jQuery you're free to useeachto iterate it.