Skip to content

All topics  /  jQuery

How to get unique values from array in Jquery?

jQuery ·

Hi Guys,

In this example,I will learn you how to remove unique values from array in jquery.you can easy and simply remove remove unique values from array in jquery.

So, here i will give you very simple example of jquery get unique values from json array with output.

Example :


<!DOCTYPE html>
<html>
<head>
   <title>How to get unique values from array in Jquery? - Nicesnippets.com</title>
   <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<body>

  
<script type="text/javascript">
    var sites = ["keval","mehul","dharmik","keval"];

  
    var uniqueSites = sites.filter(function(item, i, sites) {
        return i == sites.indexOf(item);
    });

  
    console.log(uniqueSites);
</script>

  
</body>
</html>

Output:

["keval","mehul","dharmik"]

It will help you...