Skip to content

getPath

Subhajit Sahu edited this page Jun 28, 2020 · 3 revisions

Gets value at path in a nested object. 🏃 📼 📦 🌔 📒

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

object.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