I am trying to create a new array with it's key being the index of the old array
var array = [
{"tom": "red", "part":"green", "brow_id":45},
{"tom": "red", "part":"yellow", "brow_id":1},
{"tom": "red", "part":"yellow", "brow_id":2},
{"tom": "maroon", "part":"cyan", "brow_id":45}
];
var newarray = {};
array.forEach(function(elem) {
newarray[elem.brow_id] = elem;
});
The newly formed array is like this
45: {"tom": "red", "part":"green", "brow_id":45},
1: {"tom": "red", "part":"yellow", "brow_id":1},
2: {"tom": "red", "part":"yellow", "brow_id":2},
I want it to contain all the id's of the old array like this
45: [{"tom": "red", "part":"green", "brow_id":45},{"tom": "maroon", "part":"yellow", "brow_id":45}]
1: {"tom": "red", "part":"yellow", "brow_id":1},
2: {"tom": "red", "part":"yellow", "brow_id":2},
What's wrong?
newly formed arrayu saying is just an object .