How to remove duplicate value from array in Jquery?

By Hardik Savani | January 18, 2019 | | 26314 Viewer | Category : Javascript jQuery


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? - ItSolutionStuff.com</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...



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.


We are Recommending you: