JavaScript

How to remove duplicates from JavaScript array?

How to remove duplicates from JavaScript array?, someone asked me to explain?

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

Post your comments / questions