Avatar ·

How to save JavaScript objects in localStorage or sessionStorage?

Hello everyone! I'm a beginner frontend developer and I've encountered this problem: I'm trying to save an object in localStorage, but instead of data I get the string "[object Object]". \n\nHere's my code:\n\n```javascript\nconst user = {\n name: 'Alexey',\n age: 28,\n isAdmin: true\n};\n\nlocalStorage.setItem('currentUser', user);\nconst savedUser = localStorage.getItem('currentUser');\nconsole.log(savedUser); // Outputs "[object Object]"\n```\n\nI expected to save the entire object and then be able to use it as a regular object, but localStorage apparently only works with strings. How do I properly save and retrieve objects? Do I need to use JSON? And what about nested objects or arrays? \n\nI'm also interested in whether there are size limitations for data? In my project I plan to save