Jquery

How to get unique values from array in Jquery?

Pinterest LinkedIn Tumblr
<!DOCTYPE html>
<html>
<head>
   <title>Get unique values from array in Jquery - Real Programmer</title>
   <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<body>
  <h1>Check unqiue value in console</h1>
<script type="text/javascript">
    var user_name = [ "Siddharth", "Saurabh", "Siddharth", "Yash","Yash","Saurabh" ];
  
    var uniquename = user_name.filter(function(item, i, user_name) {
        return i == user_name.indexOf(item);
    });
  
    console.log(uniquename);
</script>
  
</body>
</html>
<!-- 
OUTPUT: 
(3) ["Siddharth", "Saurabh", "Yash"]
 -->

Write A Comment