Click here to Skip to main content
11,712,454 members (74,510 online)
Click here to Skip to main content

Tagged as

Get Unique Values from a JavaScript Array

, 5 Aug 2013 CPOL 23.1K 3
Rate this:
Please Sign up or sign in to vote.
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 jQuery to do a look up.

Introduction

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 a unique list of values out of a JavaScript array. It makes use of jQuery to do a look up.

Using the code

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;
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Manas Bhardwaj
Architect
Netherlands Netherlands
Read my personal blog at www.manasbhardwaj.net.

You may also be interested in...

Comments and Discussions

 
QuestionDoes this work for arrays of objects or just primitives? Pin
AmoebaMan17-25-Aug-13 12:20
memberAmoebaMan17-25-Aug-13 12:20 
AnswerRe: Does this work for arrays of objects or just primitives? Pin
Florian Rappl5-Aug-13 12:39
mvpFlorian Rappl5-Aug-13 12:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150819.1 | Last Updated 5 Aug 2013
Article Copyright 2013 by Manas Bhardwaj
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid