JQuery Remove Multiple Values from Array Example
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
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- JQuery Moment JS Subtract Hours to Datetime Example
- JQuery Moment Subtract Year from Date Example
- How to Print Iframe Content using Jquery?
- JQuery Radio Button Change Event Example
- How to Remove Element from Array in JQuery?
- How to Get Unique Values from Array in JQuery?
- How to Remove Key Value from Array using JQuery?
- Javascript Convert Array into Comma Separated String Example
- How to Get Last Element from Array using JQuery?
- JQuery Check If Value Exists or Not in Array Example
- How to Check Array Is Empty Or Null In Javascript?
- Add Edit Delete Table Row Example using JQuery
- How to Remove Empty or Null Values from Array in JQuery?
- How to Remove Duplicate Value from Array in JQuery?