
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
array-unique-proposal
Advanced tools
ECMAScript proposal for Deduplicating method of Array.
Deduplication is one of the most common requirements in Data processing, especially in large Web Apps nowadays.
In Lodash, *uniq*
methods are also very popular:
# | Name | Downloads |
---|---|---|
1 | uniq | 5,546,070 |
7 | uniqby | 447,858 |
28 | uniqwith | 15,077 |
But [...new Set(array)]
in ECMAScript 6 isn't enough for Non-primitive values, and now, we may need a Array.prototype.uniqueBy()
.
While Array.prototype.uniqueBy()
invoked with:
no parameter, it'll work as [...new Set(array)]
;
one index-key parameter (Number
, String
or Symbol
), it'll get values from each array element with the key, and then deduplicates the origin array based on these values;
one function parameter, it'll call this function for each array element, and then deduplicates the origin array based on these returned values.
Notice:
0
& -0
are treated as the sameNaN
s are treated as the same[1, 2, 3, 3, 2, 1].uniqueBy(); // [1, 2, 3]
const data = [
{ id: 1, uid: 10000 },
{ id: 2, uid: 10000 },
{ id: 3, uid: 10001 }
];
data.uniqueBy('uid');
// [
// { id: 1, uid: 10000 },
// { id: 3, uid: 10001 }
// ]
data.uniqueBy(({ id, uid }) => `${id}-${uid}`);
// [
// { id: 1, uid: 10000 },
// { id: 2, uid: 10000 },
// { id: 3, uid: 10001 }
// ]
A polyfill is available in the core-js library. You can find it in the ECMAScript proposals section.
A simple polyfill from the proposal repo write in TypeScript.
FAQs
ECMAScript proposal for Deduplicating method of Array
The npm package array-unique-proposal receives a total of 39 weekly downloads. As such, array-unique-proposal popularity was classified as not popular.
We found that array-unique-proposal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.