Tuesday, 6 August 2013

Get Unique Values from Array in JavaScript code !

I've seen this one question, so many times in other forums, so i've decided to put it as best, simple tip.
Here is the simple code snippet to get an unique list of the values which out of a JavaScript array.
It can be makes use of jQuery to do a good look up.


Use This Code i've written !


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;

}


As soon as Comment on this post if you like or helpful !

No comments:

Post a Comment