Answers for "javascript loop nested object"

1

javascript loop nested object

function nestedLoop(obj) {
    const res = {};
    function recurse(obj, current) {
        for (const key in obj) {
            let value = obj[key];
            if(value != undefined) {
                if (value && typeof value === 'object') {
                    recurse(value, key);
                } else {
                  	// Do your stuff here to var value
                    res[key] = value;
                }
            }
        }
    }
    recurse(obj);
    return res;
}
Posted by: Guest on April-07-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language