I need to convert a JavaScript object of one type:
object1: [{"a":"value1", "b":"value2", "c":"value3"}, {"d":"value4","e":"value5","f":"value6"}]
To another type of object:
object2 : {"value1":["value1", "value2", "value3"], "value4":["value4","value5","value6"]}
I tried to convert it using this function:
function toObject(arr) {
var rv = {};
for (var i = 0; i < arr.length; ++i) {
rv[i] = arr[i];
}
return rv;
}
but I’m getting numerical indexes ([0], [1]) instead of “value1” and “value4”. Could you please give me some hint how can I do the conversion from object1 to object2. Thanks.
what you want is to concatenate the vectors inmates?
Try:
If this is not what you are looking for then try this:
[Fixed (with the help of user @user1689607)]
[edit]:
Object.keysdoes not work in older browsers. [Fixed]