🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

get-nested-val

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-nested-val

Get value of an object using an array.

1.0.1
latest
Source
npm
Version published
Weekly downloads
2
-60%
Maintainers
1
Weekly downloads
 
Created
Source

get-nested-val

A simple method to safely access nested values in an object.

Installation

npm i --save-dev get-nested-val

Module

import getVal from 'get-nested-val';

Usage

Once installed, it can be used in js as

  const get = getVal.get;
  const result = {
    books: {
      chapters: [
        { title: 'Hello World!', authors: [ 'Jason fried', 'Paul Kinlan' ] },
        { title: 'JS For Beginners', authors: [ 'Yehuda Katz' ] },
        { title: 'Node For Beginners', authors: [] },
        { title: 'Software Development', authors: [ 'Martin Fowler', 'Donald Knuth', 'Linus Torvalds'] },
      ]
    }
  }

  const getPosts = get(['books', 'chapters'])
  console.log('=====correct======', get(['books', 'chapters', 0, 'authors'], result));
  console.log('=====wrong key======', get(['books', 'chapter', 0, 'authors'], result));
  console.log('=====chaining======', get(['books', 'chapters'], result).map(el => get(['authors'], el)))
  console.log('=====curryd======', getPosts(result));
  console.log('=====path undefined======', get(undefined, result));
  console.log('=====path empty======', get([], result));
  console.log('=====path String======', get('', result));
  console.log('=====path object======'), get({}, result);

FAQs

Package last updated on 29 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts