Skip to content

Deep dive into plain object and take value by key chaining.

License

Notifications You must be signed in to change notification settings

util-funcs/object-get

Repository files navigation

object-get

Deep dive into plain object and take value by key chaining.

npm version Build Status

Getting Started

import get from '@util-funcs/object-get';

Installing

npm i @util-funcs/object-get --save

or

yarn add @util-funcs/object-get

Examples

const data = {
  name: 'John',
  surname: 'Doe',
  age: 34,
  location: {
    city: 'Londra',
    country: 'UK',
  },
  orders: [
    {
      name: 'Headphone',
      price: 45.6,
      type: 'electronic',
    },
    {
      name: 'Macbook Air 13.3 inch',
      price: 45.6,
      type: 'electronic',
    },
  ],
  '#hobbies': ['travel', 'edm'],
};
  get('name', data)) === 'John'

  get('location.city', data) === 'Londra'

  get('#hobbies[0]', data) === 'travel'

  get('orders[0]name', data) === 'Headphone'

  get('orders[0]name.length', data) === 9

  get('orders[0]category', data, 'uncategorized') === 'uncategorized'

Run tests

npm test

Built With

Versioning

We use SemVer for versioning.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details