How to remove specific value from array using jQuery ?

Given an array elements and the task is to remove the specific value element from the array with the help of JQuery. There are two approaches that are discussed below:

Approach 1: We can use the not() method which removes the element that we want. Later, use get() method to get the rest of the elements from the array.

  • Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE HTML>
    <html>
      
    <head>
        <title>
            Remove certain property for all objects
            in array with JavaScript.
        </title>
      
        <script src=
        </script>
    </head>
      
    <body style="text-align:center;">
      
        <h1 style="color: green">
            GeeksForGeeks
        </h1>
      
        <p id="GFG_UP"></p>
      
        <button onclick="gfg_Run()">
            Click Here
        </button>
      
        <p id="GFG_DOWN" style="color:green;"></p>
      
        <script>
            var el_up = document.getElementById("GFG_UP");
            var el_down = document.getElementById("GFG_DOWN");
            var arr = ["GFG", "GeeksForGeeks", "Geek", "Geeks"];
            var remEl = "Geek";
            el_up.innerHTML = "Click on the button to perform "
                    + "the operation.<br>Array - [" + arr + "]";
                      
            function gfg_Run() {
                var arr2 = $(arr).not([remEl]).get();
                el_down.innerHTML = "[" + arr2 + "]";
            
        </script>
    </body>
      
    </html>

    chevron_right

    
    

  • Output:

Approach 2: We can use the inArray() method to get the index of the element (that is to be removed) and then use slice() method to get the rest of the elements.

  • Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE HTML>
    <html>
      
    <head>
        <title>
            Remove certain property for all objects
            in array with JavaScript.
        </title>
      
        <script src=
        </script>
    </head>
      
    <body style="text-align:center;">
      
        <h1 style="color: green">
            GeeksForGeeks
        </h1>
      
        <p id="GFG_UP"></p>
      
        <button onclick="gfg_Run()">
            Click Here
        </button>
      
        <p id="GFG_DOWN" style="color:green;"></p>
      
        <script>
            var el_up = document.getElementById("GFG_UP");
            var el_down = document.getElementById("GFG_DOWN");
            var arr = ["GFG", "GeeksForGeeks", "Geek", "Geeks"];
            var remEl = "Geek";
            el_up.innerHTML = "Click on the button to perform "
                    + "the operation.<br>Array - [" + arr + "]";
                      
            function gfg_Run() {
                arr.splice($.inArray(remEl, arr), 1);
                el_down.innerHTML = "[" + arr + "]";
            
        </script>
    </body>
      
    </html>

    chevron_right

    
    

  • Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.