How to get unique values from array in Jquery?
Today, i will give you example of get unique values from json array in jquery. you will understand how to get get unique values from array in Jquery. we can easily get distinct values from array jquery.
After long time i am going to write jquery post with json array. here i decide to give you simple of getting unique values from jquery array. most of projects we need to work with json array and manage it different way.
So, here i will give you very simple example of jquery get unique values from json array with output.
Solution:
var uniqueSites = sites.filter(function(item, i, sites) {
return i == sites.indexOf(item);
});
Example:
<!DOCTYPE html>
<html>
<head>
<title>How to get unique values from array in Jquery? - ItSolutionStuff.com</title>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<body>
<script type="text/javascript">
var sites = [ "ItSolutionStuff.com", "HDTuto.com", "NiceSnippets.com", "ItSolutionStuff.com" ];
var uniqueSites = sites.filter(function(item, i, sites) {
return i == sites.indexOf(item);
});
console.log(uniqueSites);
</script>
</body>
</html>
Output:
["ItSolutionStuff.com", "HDTuto.com", "NiceSnippets.com"]
I hope it can help you...

Hardik Savani
I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to convert php array to json object with example?
- How to get last element from array object in Javascript or JQuery?
- Jquery check if value exists in Array Example
- How to remove empty and null values from json object in jquery?
- How to check if key exists in json object in jquery?
- Jquery - How to remove empty or null values from array?
- JQuery - How to push specific key and value in array?
- How to Parse JSON in JQuery Ajax?