Skip to content

hdkhoa162/get-nested-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published