Categories
JavaScript Answers

How to update and delete a cookie with JavaScript?

Spread the love

To update and delete a cookie with JavaScript, we set the document.cookie string.

For instance, we write

document.cookie = "username=Arnold";

to set document.cookie to the cookie string with the key and value.

We remove the cookie by adding the expires key and setting its value to a date in the past.

Conclusion

To update and delete a cookie with JavaScript, we set the document.cookie string.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *