can-key/get/get
Get properties on deep/nested objects of different types: Object, Map, can-reflect types, etc.
get(obj, path)
Parameters
- obj
{Object}
:the object to use as the root for property-based navigation
- path
{String}
:a String of dot-separated keys, representing a path of properties
Returns
{*}
:
the value at the property path
A path is a dot-delimited sequence of zero or more property names, such that "foo.bar" means "the property 'bar' of the object at the property 'foo' of the root." An empty path returns the object passed.
var get = require("can-key");
console.log(get({a: {b: {c: "foo"}}}, "a.b.c")); // -> "foo"
console.log(get({a: {}}, "a.b.c")); // -> undefined
console.log(get([{a: {}}, {a: {b: "bar"}}], "a.b")); // -> "bar"
var map = new Map();
map.set("first", {second: "third"});
get(map, "first.second") //-> "third"