Suppose I have this code:
var myArray = new Object();
myArray["firstname"] = "Bob";
myArray["lastname"] = "Smith";
myArray["age"] = 25;
Now if I wanted to remove "lastname"?....is there some equivalent ofmyArray["lastname"].remove()
?
(I need the element gone because the number of elements is important and I want to keep things clean.)
Answer
Use the "delete" keyword in Javascript.
delete myArray["lastname"];
EDIT:
In some JavaScript engine, the delete keyword might hurt performance as it will undo compile / JIT optimization.
http://www.html5rocks.com/en/tutorials/speed/v8/
http://www.smashingmagazine.com/2012/11/writing-fast-memory-efficient-javascript/
No comments:
Post a Comment