'LocalStorage is getting [object Object]

I am trying to retrieve the data stored in local storage but I get the value as [object Object]. I know that local storage only takes strings and the data has to be JSON.stringify when setting and JSON.parse when getting but I still get it as [object Object].

Instead of [object Object] I want to display the value entered in the input field

I am trying to get a list of items on button click. To do this I am saving the value entered in the input field and pushing it to an array.

I have created an empty array like var todosArr = Array();

when a value is entered in the input field and the submit button is clicked, this is the code executed

todosArr.push({"listname":todoTxtField.value});
localStorage.setItem('todos', JSON.stringify(todosArr));

and to display the listing in the span this is the code written

listSpan.innerText = JSON.parse(localStorage.getItem('todos'));



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source