clock  Mon - Sun 8.00 AM - 8.00 PM
mail  edu@teknowize.com
fb
instagram
play store
pinterest

How to Remove Specific Value From Array By Value Using jQuery

  Sumit Dey Sarkar
  23 Aug 2022
  JQuery
Imperial Advance Hero Image

How to Remove Specific Value From Array By Value Using jQuery

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