[Home] >  Object >  Get the value at given path of an object

Get the value at given path of an object

JavaScript version

const getValue = (path, obj) => path.split('.').reduce((acc, c) => acc && acc[c], obj);

Examples

getValue('a.b', { a: { b: 'Hello World' } }); // 'Hello World';