So I have this data:
const data = [
{
product_name: 'BMW',
year: '1982'
},
{
product_name: 'BMW',
year: '1998'
},
{
product_name: 'LandRover',
year: '1982'
},
{
product_name: 'BMW',
year: '1982'
},
{
product_name: 'LandRover',
year: '1985'
},
{
product_name: 'LandRover',
year: '1981'
}
]
Using vanilla javascript I need to filter the data into an array like this:
[
{
name: 'BMW',
data: [1982, 1998, 1982]
},
{
name: 'LandRover',
data: [1982, 1985, 1981]
}
]
Can anyone help? Not sure the best way to approach this.
Many thanks