My code run well on browser, however when run by node index.js I get this error :
let x = (agr[item.id] ??= { id: item.id, count: 0 });
^
SyntaxError: Unexpected token '?'
This is my code
var array = [{"id":1,"count":100},{"id":2,"count":200},{"id":1,"count":200}]
const groupedData = array.reduce((agr,item)=>{
let x = (agr[item.id] ??= { key: item.id, count:0 });
x.count+=(item.count);
return agr
},{});
const result = Object.entries(groupedData).reduce((agr, item) => {
agr.push(item);
return agr;
}, []);
console.log(result);
Thanks for your attention
let x = (agr[item.id] ??= { key: item.id, count:0 });should belet x = (agr[item.id] = { key: item.id, count:0 });??=only supported in Node 15.x. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…