navigation
JavaScript

How to remove duplicates from JavaScript array?

| | JavaScript

In this article we will discuss how to remove duplicates from JavaScript array. This can be implemented by using filter() method.

Example:

<script type="text/javascript">

    var myArray = ["rasik", "thivan", "mydeen", "rasik"];

    var uniqueItems = myArray.filter(function (value, index, array) {

        return array.indexOf(value) == index

    });

    alert(uniqueItems);

 

  </script>

Output:

remove duplicate from array