Skip to content

Latest commit

 

History

History
12 lines (11 loc) · 406 Bytes

js-cookbook.md

File metadata and controls

12 lines (11 loc) · 406 Bytes

Go through an object and replace values if the current value meets a condition (eg replace values of null with and empty string)

const initialValues = Object.keys(initialValuesWithNulls).reduce((acc, current) => {
    if (initialValuesWithNulls[current] === null) {
        acc[current] = '';
    } else {
        acc[current] = initialValuesWithNulls[current];
    }
    return acc;
}, {});