Deep dive into plain object and take value by key chaining.
import get from '@util-funcs/object-get';
npm i @util-funcs/object-get --save
or
yarn add @util-funcs/object-get
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'
npm test
We use SemVer for versioning.
- Ahmet ATAY - Initial work
This project is licensed under the MIT License - see the LICENSE.md file for details