Skip to content

getPath

Subhajit Sahu edited this page Dec 8, 2022 · 3 revisions

Get value at path in a nested object.

Similar: hasPath, getPath, removePath$.
Similar: get, getAll, getPath.
Similar: get, set, swap, remove.


function getPath(x, p)
// x: a nested object
// p: path
const object = require('extra-object');

var x = {a: {b: 2, c: 3}, d: 4};
object.getPath(x, ['d']);
// → 4

object.getPath(x, ['a', 'b']);
// → 2

object.getPath(x, ['a', 'b', 'c']);
// → undefined


References

Clone this wiki locally