

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I store JavaScript objects in cookies?
To store JavaScript objects in cookies, use JSON stringify. It is used to convert a JavaScript value to a JSON string.
The following code snippet to learn how to store JavaScript objects in cookies −
(function(){ var myObject = JSON.parse('{"id":1,"gender":"male"}'); var e = 'Thu Nov 26 2017 15:44:38'; document.cookie = 'myObj='+ JSON.stringify(myObject) +';expires=' + e; })()
- Related Questions & Answers
- How much data can I store in JavaScript cookies?
- How can I delete all cookies with JavaScript?
- How to store large data in JavaScript cookies?
- How can I list all cookies on the current page with JavaScript?
- How can I merge properties of two JavaScript objects dynamically?
- Can we store objects in an array in Java?
- How can I update child objects in MongoDB?
- How to store custom objects in NSUserDefaults?
- How can I serialize python objects to XML?
- How can I make my custom objects Parcelable?
- How can I make my custom objects Serializable?
- How can I update child objects in MongoDB database?
- How can I find the index of a 2d array of objects in JavaScript?
- How can I filter JSON data with multiple objects?
- How can I concatenate str and int objects in Python?
Advertisements