const arr = [
{ id0: 200, sum0: 1000 },
{ id0: 200, sum0: 1000 },
{ id0: 200, sum0: 1000 },
{ id0: 200, sum0: 1000 },
{ id10: 300, sum300: 1500 },
{ id10: 300, sum300: 1500 },
{ id10: 300, sum300: 1500 },
];
const calc = arr.reduce(
(acc, current) => {
const key = Object.keys(current).find((key) => key.startsWith("id"));
acc[key] ? acc[key]++ : (acc[key] = 1);
if (acc[key] > acc.result.count) acc.result = { id: key, count: acc[key] };
return acc;
},
{ result: { id: null, count: 0 } }
);
console.log(calc.result)