In this article we will learn how to remove specific value from array by value using jQuery.
Here we will use splice() and inArray() to remove specific values from array using jQuery,
lets see two examples in which we use different methods-
1) How to remove specific value from array by value using jQuery
<!DOCTYPE html>
<html>
<head>
<title>How to remove specific value from array by value using jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<body>
<p id="remainigValues"></p>
<script>
var popularSites = ["teknowize.com", "W3School.com", "tutorialpoint.com", "stackoverflow.com"];
popularSites.splice($.inArray('W3School.com', popularSites), 1);
$('#remainigValues').text(popularSites);
</script>
</body>
</html>
Output
teknowize.com,tutorialpoint.com,stackoverflow.com
2) How to remove specific value from array by value using jQuery
<!DOCTYPE html>
<html>
<head>
<title>How to remove specific value from array by value using jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<body>
<p id="remainigValues"></p>
<script>
var popularSites = ["teknowize.com", "W3School.com", "tutorialpoint.com", "stackoverflow.com"];
var removeItem = "W3School.com";
var popularSitesNew = $.grep(popularSites, function (value) {
return value != removeItem;
});
$('#remainigValues').text(popularSitesNew);
</script>
</body>
</html>
Output
teknowize.com,tutorialpoint.com,stackoverflow.com