String object notation to value reference

Posted on December 22, 2021

Here the cleanest way to get the object value from a string representation of the dot notation path:

const key = 'a.b.c'
const ob = {a: {b: {c:true}}}

const prop = key.split('.').reduce((o, i) => o[i], ob)