In this article we will learn how to remove multiple elements from array using value in jQuery.
Here we will use Array.prototype.remove, grep(), and inAray() to remove multiple values from array using jQuery,
lets see the example -
How to remove multiple values from array by value using jQuery
<!DOCTYPE html>
<html>
<head>
<title>How to Remove Multiple Elements From Array Using Value in jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<body>
<p id="remainigValues"></p>
<script>
var devlompentSites = ["teknowize.com", "W3School.com", "tutorialpoint.com", "stackoverflow.com"];
Array.prototype.remove = function () {
var args = Array.apply(null, arguments);
return $.grep(this, function (value) {
return $.inArray(value, args) < 0;
});
}
remainingDevlompentSites = devlompentSites.remove("W3School.com", "tutorialpoint.com");
$('#remainigValues').text(remainingDevlompentSites);
</script>
</body>
</html>
Output
teknowize.com,stackoverflow.com