Array.prototype.reduceRightadvancedconst obj = {a: {b: {c: 42}}}
['a', 'b', 'c'].reduce((acc, key) => acc[key], obj) // β 42Use reduce() (or reduceRight()) to safely drill into a nested object with a path array.
Given keys ['a', 'b', 'c'] and a value, build a deeply nested object: { a: { b: { c: value } } }.
reduceRight() lets you wrap from the inside out.
buildNested(['a', 'b', 'c'], 42) // { a: { b: { c: 42 } } }