I have an JavaScript object like this:
id="1";
name = "serdar";
and I have an Array which contains many objects of above. How can I remove an object from that array such as like that:
obj[1].remove();
I have an JavaScript object like this:
and I have an Array which contains many objects of above. How can I remove an object from that array such as like that:
|
||||
|
Well splice works:
Do NOT use the delete 'delete' operator on Arrays. But maybe you want something like this?
Just an example. |
||||
|
You can use either the The main difference is that when you delete an array element using the Example using the
Example using the
|
||||
|
Use the splice method. (At least I assume that is the answer, you say you have an object, but the code you give just creates two variables, and there is no sign of how the Array is created) |
|||
|
Use delete-keyword.
EDIT: see: http://stackoverflow.com/questions/500606/javascript-array-delete-elements delete will undefine the offset but not completly remove the entry. Splice would be correct like David said. |
|||||||||||||
|
Note that this will not change array indices. Any array members you delete will remain as "slots" that contain |
|||
|
If it's the last item in the array, you can do |
|||
|
If you know the index that the object has within the array then you can use splice(), as others have mentioned, ie:
If you don't know the index then you need to search the array for it, ie:
Marcelo |
|||
|