In lodash, I want to convert an array of objects into a single object containing 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 merge / modify them as follows:
{
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 exclusively with the built-in lodash or js functions without any loops.
Edit: I have already implemented the solution proposed by Nenad. I want a utility function in lodash.