Navigate back to the homepage

how to remove item from object in react native?

Infinitbility
React Native
August 10th, 2022 · 1 min read
how to remove item from object in react native?

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To remove item from object in react native, use delete keyword it will remove key value pair from object only you have to mantion delete keyword with key.

Let’s see how to use delete keyword to remove item from object.

1let exampleObject = {
2 id: 1,
3 name: "infinitbility",
4 error: "Feild required"
5};
6console.log("exampleObject", exampleObject);
7
8// Output
9// 'exampleObject' {
10// id: 1,
11// name: 'infinitbility',
12// error: 'Feild required'
13// }
14
15delete exampleObject.error;
16console.log("exampleObject", exampleObject);
17
18// Output
19// 'exampleObject' { id: 1, name: 'infinitbility' }

Today, I’m going to show you How do I remove item from object in react native, as above mentioned, I’m going to use the above-mentioned delete keyword to delete object item.

Let’s start today’s tutorial how do you remove item from object in react native?

React native remove item from object example using Escape characters

Here, we will take sample object state with some data and remove item in useEffect and print object to screen.

1import React, { useState, useEffect } from "react";
2import { Text, View } from 'react-native';
3export default function App() {
4 const [obj, setObj] = useState({
5 id: 1,
6 name: "infinitbility",
7 error: "Feild required"
8 });
9
10 useEffect(() => {
11 let newObj = { ...obj };
12 delete newObj.error;
13 setObj(newObj);
14 }, []);
15
16 return (
17 <View>
18 <Text>{JSON.stringify(obj)}</Text>
19 </View>
20 );
21}

I hope it helps you, All the best 👍.

Output

React Native, remove item from object example
React Native, remove item from object example

Try it yourself

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 remove item from object in typescript?

How to remove item from object in typescript?

An example of remove item from object in typescript with the step-by-step guide.

August 9th, 2022 · 1 min read
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
© 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]