bubble-gum-get

0.0.10 • Public • Published

bubble-gum-get

Get a property from a nested object or a nested array using an array path

bubble-gum-get is part of bubble-gum-tools, check this here

Install

You can install bubble-gum-get using npm.

npm install --save bubble-gum-get

API Reference

bubble-gum-get

module.exports(target, path, [defaultValue]) ⇒ *

It gets a property from a nested object or a nested array using an array path

Kind: Exported function
Returns: * - propertyValue

Param Type Description
target Object | Array Target object or target array
path Array Path to property
[defaultValue] * Value to be returned in case the property does not exist

Example

 
 const get = require('bubble-gum-get');
 
 const target = {
   root: {
     foo: 'bar',
   },
   arr: [[
     ['baz'],
   ]],
 };
 
 // Working with nested objects
 const bar = get(target, ['root', 'foo']);
 console.log(bar); // => 'bar'
 
 // Working with nested arrays
 const baz = get(target, ['arr', 0, 0, 0]);
 console.log(baz); // => 'baz'
 
 // Set a default
 const defaultVal = get(target, ['no', 'defined'], 'default');
 console.log(defaultVal); // => 'default'
 

License

MIT @ Nicolas Quiceno

Package Sidebar

Install

npm i bubble-gum-get

Weekly Downloads

9

Version

0.0.10

License

MIT

Last publish

Collaborators

  • nquicenob