In lodash, I want to convert an array of objects to a single object that contains an array of each property.
I have an array of objects:
var students = [{
name: 'A',
idNo: 1,
marks: {
math: 98,
sci: 97,
eng: 89
}
}, {
name: 'B',
idNo: 2,
marks: {
math: 88,
sci: 87,
eng: 79
}
}, {
name: 'C',
idNo: 3,
marks: {
math: 87,
sci: 98,
eng: 91
}
}]
I want to combine / reshape them like this:
{
name: [A, B, C],
idNo: [1, 2, 3],
marks: [{
math: 98,
sci: 97,
eng: 89
}, {
math: 88,
sci: 87,
eng: 79
}, {
math: 87,
sci: 98,
eng: 91
}
}]
}
I want this to be done purely with lodash or js inbuilt functions without any loops.
Edit : I have already implemented a solution as suggested by Nenad. I want a utility function in lodash.