[Solved] Merge duplicate array of object key to single array
var myArray = [ {productId: 116605, productserialno: “324234”}, {productId: 106290, productserialno: “12121”}, {productId: 106290, productserialno: “12121”}, {productId: 106293, productserialno: “4324343”} ]; var grouped = myArray.reduce(function (obj, product) { obj[product.productId] = obj[product.productId] || []; obj[product.productId].push(product.productserialno); return obj; }, {}); var groups = Object.keys(grouped).map(function (key) { return {product: key, productserialno: grouped[key]}; }); var pre = document.createElement(“pre”); pre.innerHTML … Read more