@alexaivars/get-in
v2.2.0
Published
Get a value from object by path
Downloads
6
Maintainers
Readme
getIn
Get a value from object by path. Path can be a number string or array. When any value in a path is undefined then getIn will return undefined or defaultValue if this is provided.
Installation
yarn add @alexaivars/get-in
Usage
const getIn = require("@alexaivars/get-in");
const context = {
foo: {
bar: {
baz: "waldo"
}
}
};
console.log(getIn(context, ["foo", "bar", "baz"])); // waldo
console.log(getIn(context, ["foo", "quux"])); // undefined
console.log(getIn(context, ["foo", "quux"], "notSetValue")); // "notSetValue"
Tests
yarn test