[Home] > Snippets  > Languages  > JavaScript  > Objects  >  Get the value at given path of an object

Get the value at given path of an object

JavaScript

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

Examples

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