今天才知道,在如何在字典中删除一个元素。如有这样一个字典:
Code
var dic = new Object();
dic["ele1"] = "a";
dic["ele2"] = "b";
dic["ele3"] = "c";
var dic = new Object();
dic["ele1"] = "a";
dic["ele2"] = "b";
dic["ele3"] = "c";
要删除中间的元素,要怎么做?
dic["ele2"] = null; 这样吗?
错,因为null在js中也是一个对象,正确的做法是这样:
Code
delete dic["ele2"];
delete dic["ele2"];
今天又学到了点新东西。