Skip to main content Accessibility Feedback

arrayUnique.js

Remove duplicates from an array. Learn how it works.

/*!
 * Remove duplicates from an array.
 * Adapted from https://stackoverflow.com/a/23263937
 * (c) 2017 Chris Ferdinandi, MIT License, https://gomakethings.com
 * @param  {Array} arr The array
 * @return {Array}     A new array without duplicates
 */
var arrayUnique = function (arr) {
	return arr.filter(function(item, index){
		return arr.indexOf(item) >= index;
	});
};