I'm trying to remove an object from (inside?) a object literal. But I cant figure out why it doenst work.
var data=
{
"car": 3,
"boat": 2
};
data.pop(); //should remove last one?
data.splice(1, 1); // removes element with index 1?
What am I doing wrong here? And is it posible you delete the item by name? Let say remove boat.
Since its a Object not an array, delete should work
Like this:
var data=
{
"car": 3,
"boat": 2
};
alert(data["boat"]);
delete data["boat"];
alert(data["boat"]);
See it in action :
JSFiddle
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