I have saved an array in local storage and trying to use it but when I console.log the localstorage.getitem it returns
[object HTMLDivElement] I have tried to use .innerhtml or [...] on it but they didn't work. Btw, since it's an array, I have to use JSON.stringify(movieWatchlistArray):
localStorage.setItem("key",JSON.stringify(movieWatchlistArray))
let str =localStorage.getItem("key")
console.log(JSON.parse(str) )
But when I do this, it will return an empty object inside an array while when I console.log the original array it's fine so I tried to do it without JSON part, it worked but returns a string of [object HTMLDivElement]
localStorage.setItem("key",movieWatchlistArray)
let str =localStorage.getItem("key")
console.log(str)
So how to get the content of [object HTMLDivElement] I have used .innerhtml but it says can't use .innerHTML on undefined .
when you trying to save an element in localstorage you should save the .outerHTML of it, not the element itself. although it's not recommended to save the whole HTML in local storage instead save the data as an object and use it in js to render the HTML.
so in this case it will be :
movieWatchlistArray.unshift(document.querySelector(`.movie--${moviePageNumber-1}`).outerHTML)