Languages
[Edit]
EN

JavaScript - add item to localStorage

0 points
Created by:
Aleena
694

In this article, we would like to show you how to add items to localStorage in JavaScript.

Practical example

Edit

To put items into the localStorage we use setItem() method that takes two arguments: key and value.

Note:

localStorage is BOM (Browser Object Model) global object so we can also access it using window.localStorage.

Store arrays or objects

Edit

In order to store arrays or objects, you have to convert them to strings.

 

See also

Edit
  1. JavaScript - how to use localStorage

  2. JavaScript - store array in localStorage

  3. JavaScript - clear localStorage

  4. HTML5 - localStorage vs sessionStorage

References

Edit
  1. Window.localStorage - Web APIs | MDN

Alternative titles

  1. JavaScript - store value in local storage
  2. JavaScript - store value in localStorage
  3. JavaScript - insert value into localStorage
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join