JSFiddle - React, Tailwind, and code Playground
JavaScript
var x = [{
"size": "6.5",
"width": "W"
}, {
"size": "6.5",
"width": "M"
}, {
"size": "7.5",
"width": "w"
}, {
"size": "8",
"width": "M"
}, {
"size": "8",
"width": "w"
}]
var _x = x.reduce(function(p,v){
var existing = p.filter(function(item){return item.new_size === v.size})[0];
if (existing){
existing.width_group.push( v.width );
} else {
p.push( {
new_size: v.size,
width_group:[v.width]
} );
}
return p;
},[]);
console.log(_x)