filter nested array of objects code example

Example 1: filter an array of objects and match its key with values inside another array

const arr = [1, 2, 3, 4]
const brr = [2, 4]
const res = arr.filter((f) => !brr.includes(f))
console.log(res)

Example 2: javascript map value nested object

function deepMap(obj, mapfn) {
    function recurse(obj) {
        let res = {}
        console.log(JSON.stringify(obj))
        for (const key in obj) {
            const value = obj[key];
            if (value && typeof value === 'object') {
                res[key] = recurse(value);
            } else {
                res[key] = mapfn(value);
            }
        }
        return res
    }
    return recurse(obj);
}
deepMap({'a':1, 'b':{'c':3}}, (val) => val+1) //{'a':2, 'b':{'c':4}}