I have different arrays of same size like this:
var a = ["x", "y", "z"];
var b = [1,2,3];
var c = ["l", "m", "n"];
I want this to convert to an array of object like this:
final_array = [{a: 'x', b: 1, c: 'l'}, {a: 'y', b: 2, c: 'm'}, {a: 'z', b: 3, c: 'n'}]
I know I can process the arrays using loops and somehow convert this in above format. What I have tried is this way (since size of all arrays will be same):
var final_array = [];
_.forEach(a, function(value, key){
var each_list = {};
each_list.a = a[key];
each_list.b = b[key];
each_list.c = c[key];
final_array[key] = each_list;
})
console.log(final_array); // [{a: 'x', b: 1, c: 'l'}, {a: 'y', b: 2, c: 'm'}, {a: 'z', b: 3, c: 'n'}]
But this seems to be a very lengthy way and I am sure there will be some good way to do this using lodash or some other approach.
Can any one please help me with this. I already have searched enough on stack overflow and lodash documentation but could not find a better approach for this.