0

I have user data in this formate in local storage which I am storing at the time of login.

{id: 17, name: "Boss  original", email: "[email protected]", email_verified_at: null, fcm_token: "c_jxurpcQY6Qdeh0b9ZQIV:APA91bH4BKd-dIkN5N7jtv52ZH5…zUzd35AGdNIPmn1uUSMcU_oKgnO2eAM8xybXM7MJzanzFvmZH", …}
admin: 1
allowed_login: 1
api_token: null
created_at: "2021-04-07T09:08:32.000000Z"
customer_id: null

is_driver: 0
location_access: 0
name: "Boss  original"
notification: 1
online: 0
phone_number: "12345678912"
photo: "1617894632.jpg"
role_data: {id: 3, staff_id: 17, address: "Cuernavaca, Morelos, Mexico", latitude: "18.9242095", longitude: "-99.22156590000002", …}
role_id: 9
social_security_number: "1238"
status: 1
unread_notifications: [{…}]
updated_at: "2021-04-18T16:46:32.000000Z"
warehouse: null

In this object i need to update the property unread_notifications: [{…}]

How i can update that property? I can get this object like this

localStorage.getItem(USER_INFO);

and can store like this

localStorage.setItem(USER_INFO, userData);

1 Answer 1

3

You can store data like this.

localStorage.setItem(USER_INFO, JSON.stringify(userData));

You can read, update and store again.

const userData = JSON.parse(localStorage.getItem(USER_INFO));
userData.unread_notifications = ...
localStorage.setItem(USER_INFO, JSON.stringify(userData));
Sign up to request clarification or add additional context in comments.

1 Comment

for example if i have one variable notifications . then how to update userData.unread_notifications?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.