Reputation: 2982
I have:
var map = {};
map["S"] = "s";
map["C"] = "c";
map["D"] = "d";
How can I fully remove item map["S"]? I don't want to end up with a null object so using delete map["S"] wouldn't work.
Upvotes: 25
Views: 26585
Reputation: 276239
How can I fully remove item map["S"]? I don't want to end up with a null object so using delete map["S"]
delete
does clear it completely:
interface IMap {
[name: string]: string;
}
var map: IMap = {};
map["S"] = "s";
map["C"] = "c";
map["D"] = "d";
delete map["S"];
console.log(map);
console.log(map["S"],map["non-existent"]); // undefined,undefined
console.log(Object.keys(map)); // ["C","D"]
Upvotes: 43