can-key/walk/walk
walk(obj, name, keyCallback(info) )
import walk from "can-key/walk/walk";
var user = {name: {first: "Justin"}}
walk(user, "name.first", (keyInfo)=> {
// Called 2 times.
// first call:
keyInfo //-> {parent: user, key: "name", value: user.name}
// second call:
keyInfo //-> {parent: user.name, key: "first", value: user.name.first}
})
Parameters
- obj
{Object}
:An object to read key values from.
- name
{String}
:A string key name like "foo.bar".
- keyCallback
{function(info)}
:For every key value,
keyCallback
will be called back with aninfo
object containing:info.parent
- The object the property value is being read from.info.key
- The key being read.info.value
- The key's value.
If
keyCallback
returns a value other thanundefined
, the next key value will be read from that value.