Answer the question
In order to leave comments, you need to log in
How to get data out of an array?
There is an array:
[
{
id: 1,
name: "Ivan",
type: "FirstName",
},
{
id: 2,
name: "Petrov",
type: "LastName",
},
{
id: 3,
name: "Zhora",
type: "FirstName",
},
]
Answer the question
In order to leave comments, you need to log in
You can use lodash
Or_.groupBy(array, 'type')
const groupedByType = array.reduce((acc, item) => {
const arr = acc[item.type] || []
arr.push(item)
acc[item.type] = arr
return acc
}, {})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question