get-nested-object

1.0.6 • Public • Published

get-nested-object! Build Status NPM total downloads

This plugin helps find and return a nested object or array included in parent arrays or objects.

Install

Install with npm:

npm install --save get-nested-object

Usage

// Find and return a nested object or array included in parent arrays or objects.
 
// Exp1
var getNestedObject = require('get-nested-object');
const obj = {
            id: 101,
            email: 'jack@dev.com',
            personalInfo: {
                name: 'Jack',
                address: {
                    line1: 'westwish st',
                    line2: 'washmasher',
                    city: 'San Jose',
                    state: 'WX'
                },
                education: {
                    school: {
                        NIIT: {
                            country: { name: 'Vietnam', location: 'Asia', city: 'Saigon' },
                            country: { name: 'Canada', location: 'North America', city: 'Vancouver' },
                        },
                        NAIT: [
                            { country: 'Canada', city: 'Edmonton' },
                            { country: 'Canada', city: 'Vancouver' }
                        ]
                    }
                },
                project: [
                    { description: 'caro', language: 'c#' },
                    { description: 'snake', language: 'c++' }
                ]
            }
        };
getNestedObject(obj, 'personalInfo.education.school.NAIT.1');
// => { country: 'Canada', city: 'Vancouver' };
 
// Exp2
const obj = [1, 2, 3, 4, 5, ['a', 'b', 'c'], { firstName: 'Khoa', lastName: 'Huynh' }];
getNestedObject(obj, '5.2');
// => 'c';
 

Test

npm run test

Package Sidebar

Install

npm i get-nested-object

Weekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

6.17 kB

Total Files

7

Last publish

Collaborators

  • hdkhoa162