
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
unique-objects
Advanced tools
Get unique objects from array of objects based on single/multiple keys.
$ npm i unique-objects
This can be helpful in cases where you need unique records based on a single key or multiple keys.
const uniqueObjects = require('unique-objects');
const users = [
{ id: 1, username: 'bret' },
{ id: 2, username: 'samantha' },
{ id: 2, username: 'samantha' },
{ id: 2, username: 'samantha2' },
{ id: 3, username: 'elvis' },
{ id: 3, username: 'elvis2' },
{ id: 3, username: 'elvis2' }
];
// Get unique objects in the users array based on just id
uniqueObjects(users, ['id']);
//=> Returns just 3 unique objects out of 7
// [
// { "id": 1, "username": "bret"},
// { "id": 2, "username": "samantha2"},
// { "id": 3, "username": "elvis2"},
// ]
// Get unique objects in the users array based on both id & username
uniqueObjects(users, ['id', 'username']);
//=> Returns just 5 unique objects out of 7
// [
// { "id": 1, "username": "bret"},
// { "id": 2, "username": "samantha"},
// { "id": 2, "username": "samantha2"},
// { "id": 3, "username": "elvis"},
// { "id": 3, "username": "elvis2"},
// ]
Type: Array
Default: []
Must be a JavaScript Array. This is main array of object that we are going to process.
Type: Array
Default: []
Must be a JavaScript Array. This is the array of key(s) in the object that is used to find object is unique or not.
MIT © Palash Mondal
FAQs
Get unique objects from array of objects
The npm package unique-objects receives a total of 362 weekly downloads. As such, unique-objects popularity was classified as not popular.
We found that unique-objects demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.