Navigate back to the homepage

How to remove item from object in typescript?

Infinitbility
TypeScript
August 9th, 2022 · 1 min read
How to remove item from object in typescript?

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.

1interface ObjDTO {
2 id: number,
3 name: string,
4 error?: string,
5}
6
7let exampleObject: ObjDTO = {
8 id: 1,
9 name: "infinitbility",
10 error: "Feild required"
11};

Now, we delete the error property from the object.

1interface ObjDTO {
2 id: number,
3 name: string,
4 error?: string,
5}
6
7let exampleObject: ObjDTO = {
8 id: 1,
9 name: "infinitbility",
10 error: "Feild required"
11};
12console.log("exampleObject", exampleObject);
13
14delete exampleObject.error;
15
16console.log("exampleObject", exampleObject);

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to handle apostrophe in javascript?

how to handle apostrophe in javascript?

An example of handle apostrophe in javascript with the step-by-step guide.

August 9th, 2022 · 1 min read
how to handle apostrophe in react js?

how to handle apostrophe in react js?

An example of handle apostrophe in react js with the step-by-step guide.

August 9th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]