[Solved] Modify JSON array in Javascript


This is how you do it in plain javascript (es6)

const mergePrice = data => data.reduce((result, val) => {
   const { quoteId, price, userName } = val;
   let obj = result.find(o => o.quoteId === quoteId);
   if (!obj) {
       obj = { quoteId, userName, price: [] };
       result.push(obj);
   }
   obj.price.push(price);
   return result;
}, []);

const merged = mergePrice([{quoteId: "MqWmJkUzcP", price: 211, userName: "Test"},{quoteId: "OqgFavcIiR", price: 230, userName: "Aglowid"},{quoteId: "MqWmJkUzcP", price: 120},
 {quoteId: "IFeiWnxMfq", price: 146, userName: "Test-2"},
 {quoteId: "pVL0CgIxaN", price: 155, userName: "Test-2"}]);
 
 console.log(merged);

solved Modify JSON array in Javascript