Skip to content

Get Unique Values from a JavaScript Array using jQuery

I have seen this question so many times on forums, so decided to put it as tip. Here is a simple code snippet to get unique list of values out of JavaScript array. It makes use of jQueryto do a look up.


function GetUnique(inputArray)
{
	var outputArray = [];
	for (var i = 0; i < inputArray.length; i++)
	{
		if ((jQuery.inArray(inputArray[i], outputArray)) == -1)
		{
			outputArray.push(inputArray[i]);
		}
	}
	return outputArray;
}

If you enjoyed this article, please consider sharing it!

Further Reading:

JavaScript Prototype Chains, Scope Chains, and Performance: What You Need to Know

Published inUncategorized

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *