New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

group-objects-array

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

group-objects-array - npm Package Compare versions

Comparing version
1.0.1
to
1.0.2
+1
-0
lib/util/uniqueArray.js

@@ -21,2 +21,3 @@ "use strict";

* let arr = [{name: "John", age: 30}, {name: "Doe", age: 29}, {name: "John", age: 30}, {name: "Michel", age: 21}];
*
* uniqueArray(arr);

@@ -23,0 +24,0 @@ * // returns [{name: "John", age: 30}, {name: "Doe", age: 29}, {name: "Michel", age: 21}]

+12
-4
{
"name": "group-objects-array",
"version": "1.0.1",
"description": "\"Groups and merges array of objects by a single key\"",
"version": "1.0.2",
"description": "Groups and merges array of objects by a single key.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node ./tests/groupObjectArrayByKey.spec.js"
},

@@ -16,3 +16,11 @@ "keywords": [

"author": "Jana Rangasamy <janagr7@gmail.com>",
"license": "ISC"
"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/grjan7/group-objects-array.git"
},
"homepage": "https://github.com/grjan7/group-objects-array#readme",
"bugs": {
"url": "https://github.com/grjan7/group-objects-array/issues"
}
}
# group-objects-array
Groups JavaScript objects array by a key and returns grouped array.

@@ -6,5 +7,6 @@

Groups the scattered objects in an array based on a groupByKey (e.g. id). For the given groupByKey value, if there is a multiple occurrence of same key (e.g., contact key for id:3) but with unique values, then the values will be grouped into an array.
Groups the scattered objects in an array based on a `groupByKey` (e.g. id). For the given `groupByKey` value, if there is a multiple occurrence of same key (e.g., contact key for id: 3) but with unique values, then the values will be grouped into an array.
## Installation
```sh

@@ -16,4 +18,10 @@

## Example:
## Usage:
### `groupObjectArrayByKey(objArr, groupByKey)`
- **objArr** an array of objects to be grouped
- **groupByKey** an object key to group the objects
```js

@@ -23,3 +31,3 @@

let objArray = [
const objArray = [
{id: 1, name: "John"},

@@ -30,3 +38,3 @@ {id: 2, name: "Aaron"},

{id: 3, name: "Michel"},
{id: 1, address: {street: "123 Main Street", city: "NY", country: "USA"}}
{id: 1, address: {street: "123 Main Street", city: "NY", country: "USA"}},
{id: 3, contact: "+01-51245 53125"},

@@ -38,11 +46,52 @@ {id: 3, contact: "+02-51245 53125"},

groupObjectArrayByKey(objArray, "id");
//returns
```
returns
```js
[
{id: 1, name: "John", age: 20, address: {street: "123 Main Street", city: "NY", country: "USA"}},
{id: 2, name: "Aaron", age: 30},
{id: 3, name: "Michel", contact: ["+01-51245 53125", "+02-51245 53125"]}
{id: 1, name: "John", age: 20, address: {street: "123 Main Street", city: "NY", country: "USA"}},
{id: 2, name: "Aaron", age: 30},
{id: 3, name: "Michel", contact: ["+01-51245 53125", "+02-51245 53125"]}
]
```
### `uniqueArray(arr)`
This function returns an array with duplicates removed.
- **arr** an array to be deduplicated to have only unique values
```js
const { uniqueArray } = require("group-objects-array");
const arr = [{name: "John", age: 30}, {name: "Doe", age: 29}, {name: "John", age: 30}, {name: "Michel", age: 21}];
uniqueArray(arr);
```
returns
```js
[{name: "John", age: 30}, {name: "Doe", age: 29}, {name: "Michel", age: 21}]
```
### `isItemInArray(arr, item)`
This function checks if an item is in the given array.
- **arr** source array
- **item** item to be checked whether it is in the array
```js
const { isItemInArray } = require("group-objects-array");
const arr = [{name: "John"}, "world"];
isItemInArray(arr, {name: "John"}); // returns true
```