Skip to content

WebForgeOSS/group-values-by-key

Repository files navigation

group-values-by-key

Build Status Coverage Status Maintainability Language grade: JavaScript tested with jest code style: prettier

Group values of two objects by their key

Install

$ npm install group-values-by-key

Usage

const groupValuesByKey = require("group-values-by-key");

const objects = [{ a: 2 }, { a: 3, b: 1 }];

groupValuesByKey(objects); //=> { a: [ 2, 3 ], b: [ 1 ] }

API

groupValuesByKey(objects) ⇒ Object

group values of two objects by their key

Returns: Object - object grouping values

Param Type Description
objects Object[] array of object

Example

groupValuesByKey({ a: 2 }, { a: 3, b: 1 }); //=> { a: [ 2, 3 ], b: [ 1 ] }

License

MIT © muceres