Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A small utility that attaches an `add` method to a regular Array instance which silently ignores duplicate values.

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time


Utility that creates an Array instance with modified push, unshift, and splice methods that check for uniqueness before inserting values. This utility is pretty dumb in that it just iterates over the array looking for a value that matches using the === operator. It's not going to be fast over large arrays.


var Unique = require( 'bluejeansandrain.unique' );

var arr = new Unique();
arr.push( 'a', 'b', 'c' );
arr.push( 'a' );

console.log( arr );



Unique is not actually a class though you can use new with it. It's just a factory method that creates a regular array and then bolts a method on the side. So new is totally optional.


var arr = unique();

Unique can also be used to deduplicate existing arrays.


var dup = ['a', 'b', 'c', 'a'];
var arr = unique( dup );
console.log( arr );


Something went wrong with that request. Please try again.