Вы можете добавить данные в свое хранилище. У вас есть ключ и значение, оба должны быть строками.
window.localStorage.setItem('myCat', 'Tom');
, и вы можете получить его так:
window.localStorage.getItem("myCat");
Для хранения переменной, массива, объекта и т. Д. c. сначала вам нужно будет преобразовать его в строку, например, такую:
let arr = [1, 2, 3];
//you need to convert this array to an string.
let arr_string = JSON.stringify(arr);
//now you can store it in your local storage
window.localStorage.setItem("myArray", arr_string);
//to get the array you will need to parse it back from string to array.
let arr_string = window.localStorage.getItem("myArray");
let arr = JSON.parse(arr_string);
console.log(arr); // output: [1, 2, 3]