Returns all the keys(including nested) of an object
npm install objectkeysInstall with npm:
``sh`
$ npm install objectkeys --save
`javascript
var OBJECT_KEYS = require('objectkeys');
var object = {
'California' : 'CA',
'Texas' : 'TX',
'NEW YORK' : 'NY'
};
OBJECT_KEYS.keys(object);
//=> ['California', 'Texas', 'NEW YORK']
var days = {
'SUNDAY' : 'First',
'MONDAY' : 'Second',
'TUESDAY' : 'Third',
'WEDNESDAY' : 3
};
OBJECT_KEYS.keys(days);
//=> ['SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY']
`
`bash`
$ git clone https://github.com/luthraG/objectkeys.git
#### keys(obj, [options])
This API takes two parameters:
1. Object whose keys to be fetched and
2. options object. This argument is optional
Options
Various options supported by this API are :
- deep - To specify if nested keys should also be fethced. Default is false.
Example with options
`javascript
var OBJECT_KEYS = require('objectkeys');
var days = {
'SUNDAY' : 'First',
'MONDAY' : 'Second',
'TUESDAY' : 'Third',
'WEDNESDAY' : 3,
'WEEK_END' : {
'SUNDAY' : {
'CODE' : {
'ABBR' : 'SAT'
}
}
}
};
OBJECT_KEYS.keys(days, { deep : true});
//=> [ 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'WEEK_END', 'SUNDAY', 'CODE', 'ABBR' ]
``
You might also be interested in these projects:
* objectvalues: To get all the values of all the keys of an object. It provides options to fetch values of nested keys as well. | homepage
* uppercase-values: Convert the values of all the keys of an object into uppercase. | homepage
* lowercase-values: Convert the values of all the keys of an object into lowercase. | homepage
* object-lowerkeys: Convert the keys of an object into lowercase. | homepage
* object-upperkeys: Convert the keys of an object into uppercase. | homepage
Gaurav Luthra
MIT © Gaurav Luthra