0

Deep update object with JavaScript

Function JavaScript 1 revisions 180 a month ago a month ago
const deepUpdate = (original, replacements) => {
    return Object.keys(replacements).reduce(
        (result, key) => {
            if (typeof replacements[key] === `object`) {
                result[key] = _update(result[key], replacements[key]);
            } else {
                result[key] = replacements[key];
            }

            return result;
        },
        { ...original },
    );
};