Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In jquery how do I remove an array element either via index["key"] or value

Tags:

In jQuery/JavaScript, How do I remove an array element?

something like:

array.remove(array["key"]);  // or   array.remove("value") 
like image 762
Randel Ramirez Avatar asked Jun 23 '12 15:06

Randel Ramirez


People also ask

How do you remove an element from an array and a shift index?

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.

Which methods are used for removing any element or content in jQuery?

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.


1 Answers

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.

like image 140
Andrew Whitaker Avatar answered Dec 20 '22 00:12

Andrew Whitaker