Jquery Remove Multiple Values from Array Example

Admin   Jquery   61  2020-08-07 16:25:18

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 - </title>

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

</head>

<body>

<script type="text/javascript">

var sites = [ "", "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:

["", "Hackthestuff.com"]

I hope it can help you...