For example I have this JSON data:
const data = [
{
title: 'Nike Dunk Low Panda',
sku: 'DD1391-100',
size: '9 US',
},
{
title: 'Nike Dunk Low Panda',
sku: 'DD1391-100',
size: '10 US',
},
{
title: 'Nike Dunk Low Panda',
sku: 'DD1391-100',
size: '11 US',
},
]
How to create another array like:
const data = [
{
title: 'Nike Dunk Low Panda',
sku: 'DD1391-100',
size: '9 US, 10 US, 11 US'
}
]
I’m new in JS, trying to learn it )
3
Answers
One way to do it is to create a new array by aggregating the sizes for each unique combination of
title
andsku
title
andsku
You could group by two keys and map the result by getting the wanted property from the group.