I have a js array that looks like this : { "0": { "sourceDir": "docs", "filepath": "docs/TODO.md" }, "1": { "sourceDir": "docs", "filepath": "docs/async-chat.md" },

I won't know ahead of time what the keys, "sourceDir", "filepath" etc will be. How do I convert it to the form :

{ "sourceDir": "docs", "filepath": ["docs/TODO.md", "docs/async-chat.md"] }


    const originalArray = this.config
    message.whiteboard = Object.keys(originalArray).reduce((acc, key) => {
        const value = originalArray[key];
        Object.keys(value).forEach((prop) => {
            if (!acc[prop]) {
                acc[prop] = [];
            }
            acc[prop].push(value[prop]);
        });
        return acc;
    }, {});

    I get :
    TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at file:///home/danny/github-danny/transmissions/src/services/util/WhiteboardToMessage.js:16:20
at Array.reduce (<anonymous>)

2024-08-26.md