how to prepare key in object dyamically javascript 1

how to prepare key in object dyamically javascript

function resolve(path, obj) {
    return path.split('.').reduce(function(prev, curr) {
        return prev ? prev[curr] : null
    }, obj || self)
}

Here is what the above code is Doing:
1. It’s creating a function called resolve.
2. It’s taking two arguments: path and obj.
3. It’s splitting the path argument into an array of strings.
4. It’s using reduce to iterate through the array of strings.
5. It’s using the reduce callback to return the value of the object at the path.
6. It’s returning the value of the object at the path.

Similar Posts