SyntaxFix
Write A Post
Hire A Developer
Questions
While reduce is good, I am surprised no one used forEach:
function valueForKeyPath(obj, path){ const keys = path.split('.'); keys.forEach((key)=> obj = obj[key]); return obj; };
Test