I have 3 objects
[
{name: 3, q: 10, b: 1},
{name: 5, q: 6, b: 2},
{name: 5, q: 7, b: 1}
]
I need to group them by name:
[
{name: 3: items: [{q:10, b: 1}]},
{name: 5: items: [{q:6, b: 2}, {q:7, b: 1}]},
]
maybe there are any delicate solutions with lodash?
4
Answers
You can use Object.values combined with Array.prototype.reduce() and Array.prototype.push()
Code:
You dont need lodash, you can just use JavaScript
using forEach
using reduce and Object.values()
using map and reduce
output
You can use the following simple solution to achieve this.
Hello simply you can use for loop with find function.
i will try to help you Please check below example
I hope this help you