What is array-union?
The array-union package is designed to create an array of unique values, in order, from all given arrays. It's particularly useful for combining arrays while removing duplicate entries, ensuring that the resulting array contains only unique items.
What are array-union's main functionalities?
Creating a union of arrays
This feature allows you to combine multiple arrays into one array with unique values, effectively removing duplicates.
const arrayUnion = require('array-union');
const result = arrayUnion([1, 2], [2, 3], [3, 4]);
console.log(result); // Output: [1, 2, 3, 4]
Other packages similar to array-union
lodash.union
Lodash's union function offers similar functionality to array-union by creating an array of unique values, in order, from all given arrays. Lodash is a more comprehensive utility library, so using lodash.union might be preferable if you're already using Lodash in your project.
array-union
Create an array of unique values, in order, from the input arrays
Install
$ npm install array-union
Usage
import arrayUnion from 'array-union';
arrayUnion([1, 1, 2, 3], [2, 3]);
arrayUnion(['foo', 'foo', 'bar']);
arrayUnion(['🐱', '🦄', '🐻'], ['🦄', '🌈']);
arrayUnion(['🐱', '🦄'], ['🐻', '🦄'], ['🐶', '🌈', '🌈']);