How to remove duplicate value from array in Jquery?

Admin   JAVASCRIPT   69  2020-08-11 20:57:12

In this post, i would like to show you how to remove duplicate value from javascript array. we will use jquery filter for remove duplicates value from array. you can simply delete duplicate string in jquery array.

Actually, very few months ago i need to work with jquery array. i have multiple time duplicate value in javascript array. i don't require to display then again and again, i just want to remove that same value in jquery. i had found out the solution of remove duplicates value from array in jquery.

So, here i am going to share simple example, so you can check it:

Example:

<!DOCTYPE html>

<html>

<head>

<title>How to remove duplicate value from array in Jquery? - </title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

</head>

<body>

<script type="text/javascript">

var myArray = ["Hardik", "Paresh", "Sagar", "Hardik", "Rahul"];

var myNewArray = myArray.filter(function(elem, index, self) {

return index === self.indexOf(elem);

});

console.log(myNewArray);

</script>

</body>

</html>

Output:

Array(4)

0: "Hardik"

1: "Paresh"

2: "Sagar"

3: "Rahul"

I hope it can help you...