Jquery Remove Multiple Values from Array Example

By Hardik Savani | December 31, 2019 | Category : jQuery


in this post, i would like to give you example of how to remove multiple element from array in jquery. we can simply remove multiple values from array in jquery. you can see simple example of remove multiple items from array in jquery.

we will use Array.prototype.remove, grep() and inArray() for removing multiple values from array in jquery. you can just see bellow example it's done. you can easily use with your jquery array.

If you want to remove single item from jquery array by value then you can follow this tutorial: How to Remove Array Element in Jquery by Value?.

So let's see bellow simple example of jquery remove multiple values from array.

Example :

<!DOCTYPE html>

<html>

<head>

<title>Jquery Remove Multiple Values from Array Example - ItSolutionStuff.com</title>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

</head>

<body>

<script type="text/javascript">

var sites = [ "ItSolutionStuff.com", "HDTuto.com", "NiceSnippets.com", "Hackthestuff.com" ];

Array.prototype.remove = function(){

var args = Array.apply(null, arguments);

return $.grep(this, function(value) {

return $.inArray(value, args) < 0;

});

}

sitesNew = sites.remove("HDTuto.com", "NiceSnippets.com");

console.log(sitesNew);

</script>

</body>

</html>

Output:

["ItSolutionStuff.com", "Hackthestuff.com"]

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: