objectvalues

1.0.4 • Public • Published

objectvalues

To get all the values of all the keys of an object. It provides options to fetch values of nested keys as well.

Installation

Install with npm:

$ npm install objectvalues --save

Usage

var OBJECT_VALUES = require('objectvalues');
 
var object = {
    'California' : 'CA',
    'Texas'      : 'TX',
    'NEW YORK'   : 'NY' 
};
 
OBJECT_VALUES.values(object);
//=> ['CA', 'TX', 'NY']
 
var days = {
    'SUNDAY'    : 'First',
    'MONDAY'    : 'Second',
    'TUESDAY'   : 'Third',
    'WEDNESDAY' : 3
};
 
OBJECT_VALUES.values(days);
//=> ['First', 'Second', 'Third', 3]
 

Clone the repo

$ git clone https://github.com/luthraG/objectvalues.git

API

values(obj, [options])

This API takes two parameters:

  1. Object whose values to be fetched and
  2. options object. This argument is optional

Options

Various options supported by this API are :

  • deep - To specify if values of nested keys should also be fethced. Default is false.

Example with options

var OBJECT_VALUES = require('objectvalues');
 
var days = {
    'SUNDAY'    : 'First',
    'MONDAY'    : 'Second',
    'TUESDAY'   : 'Third',
    'WEDNESDAY' : 3,
    'WEEK_END'  : {
     'SUNDAY' : {
     'CODE' : {
     'ABBR' : 'SAT'
     }
     }
    }
};
 
OBJECT_VALUES.values(days, { deep : true});
//=> [ 'First', 'Second', 'Third', 3, 'SAT' ]
 

Related projects

You might also be interested in these projects:

Author

Gaurav Luthra

License

MIT © Gaurav Luthra

Package Sidebar

Install

npm i objectvalues

Weekly Downloads

1

Version

1.0.4

License

MIT

Last publish

Collaborators

  • gluthra