[Chartjs]-Extract arrays from JSON

2👍

It can be achieved this way:

const obj = {};
array.forEach((item) => {
    Object.entries(item).forEach(([key, value]) => {
        if(key in obj) {
            obj[key].push(value);
        } else {
            obj[key] = [value];
        }
    });
});
console.log(obj);

Leave a comment