objectvalues

Returns all the values present in an object


Keywords
object, values, properties, keys, extend, assign, value
License
MIT
Install
npm install objectvalues@1.0.0

Documentation

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