Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

To remove the item from an object in typescript, use the delete keyword it will remove the key-value pair from an object only you have to mention the delete keyword with the key.

typescript object is one of the most used concepts and we will use it every day almost but sometimes we need to delete some key-value pair.

Today, we will see how we can remove items from the typescript object using a key.

Typescript provides a delete operator to remove the item from the object we have to just write the object with the key name and it will remove the property.

let’s take a sample object like the below.

interface ObjDTO {
    id: number,
    name: string,
    error?: string,
}

let exampleObject: ObjDTO = {
  id: 1,
  name: "infinitbility",
  error: "Feild required"
};

Now, we delete the error property from the object.

interface ObjDTO {
    id: number,
    name: string,
    error?: string,
}

let exampleObject: ObjDTO = {
  id: 1,
  name: "infinitbility",
  error: "Feild required"
};
console.log("exampleObject", exampleObject);

delete exampleObject.error;

console.log("exampleObject", exampleObject);

I hope it helps you, All the best đź‘Ť.