Get the value at a specific object (or string) path, without caring if it exists
$ npm i @iamnapo/get
const get = require("@iamnapo/get");
get([4, 5], "[0]"); // => 4
get({ a: { b: 1 } }, "a.b"); // => 1
get({ a: { b: 1 } }, "a.c", "blah"); // => "blah"
get("napo", "[1]"); // => "a"
Get path
of object
, returning defaultValue
if it doesn‘t exist.
Type: object | Array | string
Base object to get value from.
Type: string
Path to get value at.
Type: string
Default: undefined
Return value if path doesn‘t exist.