@travic/get
v1.0.7
Published
A helper function when trying to access nested keys
Downloads
8
Maintainers
Readme
GET
npm i @travic/get
or
yarn add @travic/get
To use, import
or require
package;
import { get } from '@travic/get';
// or
const { get } = require('@travic/get');
// example use
const obj = {
a: 'string',
b: true,
c: {
aa: 'another string',
},
d: [1, 2, 3],
};
get(obj, 'a'); // -> 'string'
get(obj, 'b'); // -> true
get(obj, 'c'); // -> { aa: 'aa' }
get(obj, 'c.aa'); // -> 'another string'
get(obj, 'c.aa.aaa'); // -> null
get(obj, 'c.aa.aaa', "It's not here!"); // -> "It's not here!"
get(obj, 'd.1'); // -> 2
get(1, 'd.1'); // -> null