remove element from dictionary in typescript

You can remove an element from a TypeScript dictionary (type Object) using the delete keyword.

index.ts
const myDict = {foo: "bar", baz: "qux"};
delete myDict["foo"];
console.log(myDict); // Output: {baz: "qux"}
108 chars
4 lines

Alternatively, you can use the Object class's delete method.

index.ts
const myDict = {foo: "bar", baz: "qux"};
Object.delete(myDict, "foo");
console.log(myDict); // Output: {baz: "qux"}
116 chars
4 lines

Note that the delete keyword returns true if the specified property was successfully deleted, or false otherwise.

gistlibby LogSnag