Saving structures in a localStorage in JavaScript

Only strings can be stored in local storage. However, it is possible to store arrays and objects - you can simply use the JSON format for this. .

Let's save an array:

let arr = [1, 2, 3, 4, 5]; localStorage.setItem('arr', JSON.stringify(arr));

Now let's get it back:

let str = localStorage.getItem('arr'); let res = JSON.parse(str); console.log(res);

Given inputs and a button. By clicking on the button, get the texts of all inputs in the form of an array and save this array to the local storage.

Modify the previous task. Make sure that the next time you visit the page, the inputs will contain the values saved in the local storage.