JQuery Remove Multiple Values from Array Example

By Hardik Savani July 20, 2023 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...

Tags :
Shares