Skip to content

getPath

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

Get value at path in nested lists.

Alternatives: get, getAll, getPath.
Similar: hasPath, getPath.
Similar: get, set, remove.


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

var x = [['a', 'b', 'c'], [2, 4, 6]];
var y = [['x', 'e', 'f'], [x, 10, 12]];
xlists.getPath(y, ['e']);
// → 10

xlists.getPath(y, ['x', 'b']);
// → 4

xlists.getPath(y, ['x', 'b', 'c']);
// → undefined


References

Clone this wiki locally