You can do something like this
const data = [{date: 2021,name: 'New York',price: 452}, {date: 2020,name: 'New York',price: 452}, {date: 2021,name: 'Oregon',price: 452}]
const result = Object.values(data.reduce((res, {name,...rest}) => {
return {
...res,
[name]: {
name,
values: [...(res[name] || {values: []}).values, rest]
}
}
}, []))
console.log(result)
solved JavaScript: Convert array of objects into array of object of array of object