In jQuery/JavaScript, How do I remove an array element?
something like:
array.remove(array["key"]); // or array.remove("value")
To remove an array element at index i, you shift elements with index greater than i left (or down) by one element. For example, if you want to remove element 3, you copy element 4 to element 3, element 5 to element 4, element 6 to element 5.
To remove elements and content, there are mainly two jQuery methods: remove() - Removes the selected element (and its child elements) empty() - Removes the child elements from the selected element.
Judging by your code, it sounds like you want to delete an object's property, which you would do with delete
:
var obj = { key: "value" }; delete obj["key"];
A very useful guide on working with objects in JavaScript can be found on MDN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With