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

"Groups and merges array of objects by a single key"

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
1
-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

group-objects-array

Groups JavaScript objects array by a key and returns grouped array.

Summary

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.

Example:


 const { groupObjectArrayByKey } = require('./index.js');
 
 let objArray = [
  {id: 1, name: "John"},
  {id: 2, name: "Aaron"},
  {id: 1, age: 20},
  {id: 2, age: 30},
  {id: 3, name: "Michel"},
  {id: 1, address: {street: "123 Main Street", city: "NY", country: "USA"}}
  {id: 3, contact: "+01-51245 53125"},
  {id: 3, contact: "+02-51245 53125"},
  {id: 1, address: {street: "123 Main Street", city: "NY", country: "USA"}}  
 ];
  
 groupObjectArrayByKey(objArray, "id");
  
 //returns
 
 [
 {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"]}
 ]

Keywords

objects

FAQs

Package last updated on 05 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts