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:
<!DOCTYPE HTML><html><head><title>Remove certain property for all objectsin array with JavaScript.</title><scriptsrc=</script></head><bodystyle="text-align:center;"><h1style="color: green">GeeksForGeeks</h1><pid="GFG_UP"></p><buttononclick="gfg_Run()">Click Here</button><pid="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_rightfilter_none -
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:
<!DOCTYPE HTML><html><head><title>Remove certain property for all objectsin array with JavaScript.</title><scriptsrc=</script></head><bodystyle="text-align:center;"><h1style="color: green">GeeksForGeeks</h1><pid="GFG_UP"></p><buttononclick="gfg_Run()">Click Here</button><pid="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_rightfilter_none -
Output:
Recommended Posts:
- How to remove specific div element by using JavaScript?
- How to find element with specific ID using jQuery ?
- How to scroll to specific element using jQuery ?
- How to get text of specific option tag using jQuery?
- How to remove gutter space for a specific div in Bootstrap ?
- How to select all elements that contains some specific CSS property using jQuery ?
- How to reload page after specific seconds in jQuery ?
- How to check a string starts/ends with a specific string in jQuery ?
- jQuery | remove()
- jQuery | Remove Elements
- How to fadeOut and remove a div using jQuery ?
- How to Remove an Event Handler using jQuery ?
- jQuery callbacks.remove() Method
- How to Add and Remove multiple classes in jQuery ?
- How to remove CSS “top” and “left” attribute with jQuery ?
- How to Dynamically Add/Remove Table Rows using jQuery ?
- JQuery | Remove “disabled” attribute from an element
- How to remove options from select element using jQuery ?
- How to remove all inline styles using JavaScript/jQuery ?
- How to determine if an array contains a specific value in PHP?
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.


