How To Get Unique Values From Array in jQuery Tutorial

Share this Article
Reading Time: 3 minutes
544 Views

Inside this article we will see the concept i.e How To Get Unique Values From Array in jQuery. Article contains the classified information about getting unique values from array in jquery.

Selecting values from array in jquery is a very basic concept but if your array contains duplicates then you need some logic to filter out the unique values from it.

If you are looking for a solution to select the distinct values from javascript array then this article will help you a lot for this. We will use filter() method of jQuery.

Learn More –

Let’s get started.

Application Programming

Create a file index.html inside your project folder.

Open index.html and write this following code into it.

<!DOCTYPE html>
<html>
<head>
   <title>How To Get Unique Values From Array in jQuery Tutorial</title>
   <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<body>
  
<script type="text/javascript">

    var employees = ["Sanjay","Siddharth","Dhananjay","Sanjay"];
  
    var uniqueEmployees = employees.filter(function(item, i, emp) {
        return i == emp.indexOf(item);
    });
  
    console.log(uniqueEmployees);
</script>
  
</body>
</html>

Concept

Filter Unique values from array.

var uniqueEmployees = employees.filter(function(item, i, emp) {
    return i == emp.indexOf(item);
});

Application Testing

Now,

Open project into browser.

URL: http://localhost/index.html

We hope this article helped you to learn How To Get Unique Values From Array in jQuery Tutorial in a very detailed way.

Buy Me a Coffee

Online Web Tutor invites you to try Skillshare free for 1 month! Learn CakePHP 4, Laravel APIs Development, CodeIgniter 4, Node Js, etc into a depth level. Master the Coding Skills to Become an Expert in Web Development. So, Search your favourite course and enroll now. Click here to join.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Was this post helpful?

Learn Web Development Courses Risk Free @ $5 only.
Web Development Courses @ $5