Unique Array (NodeJS)
Release | Latest ( |
Pre ( |
---|---|---|
GitHub |
||
NPM |
📝 Description
A NodeJS module to return unique array elements by ignore all of the duplicated elements.
📚 Documentation
Getting Started
Install
- NodeJS >= v14.15.0
- NPM >= v6.14.8
npm install @hugoalh/unique-array
Use In CommonJS
const uniqueArray = require("@hugoalh/unique-array");
Use In ModuleJS
import uniqueArray from "@hugoalh/unique-array";
API
Function
uniqueArray(
input: any[],
ignoreReferences?: boolean = false// Whether to compare objects without compare their reference points.
): any[]
Example
uniqueArray([1, 1, 1, 2, 2, 3]);
//=> [1, 2, 3]
uniqueArray([{ foo: "bar" }, { foo: "bar" }, { bar: "gaz" }]);
//=> [{ foo: "bar" }, { foo: "bar" }, { bar: "gaz" }]
uniqueArray([{ foo: "bar" }, { foo: "bar" }, { bar: "gaz" }], true);
//=> [{ foo: "bar" }, { bar: "gaz" }]