localStorage
only supports strings. Use JSON.stringify()
and JSON.parse()
.
var names = []; names[0] = prompt("New member name?"); localStorage.setItem("names", JSON.stringify(names)); //... var storedNames = JSON.parse(localStorage.getItem("names"));
You can also use direct access to set/get item:
localstorage.names = JSON.stringify(names); var storedNames = JSON.parse(localStorage.names);
Related Posts:
- HTML5 Local storage vs. Session storage
- Showing an image from an array of images – Javascript
- For-each over an array in JavaScript
- Failed to load resource: the server responded with a status of 404 (Not Found)
- Maximum call stack size exceeded error
- Google Chrome Uncaught (in promise) DOMException while playing AUDIO
- Find object by id in an array of JavaScript objects
- How to make a word underline in Markdown
- ChartJS beginAtZero, min, max doesn’t work
- how to fix : ” TypeError: Cannot read property ‘addEventListener’ of null”…?//
- Cannot set property InnerHTML of null [duplicate]
- ReferenceError: $ is not defined
- React.js: Set innerHTML vs dangerouslySetInnerHTML
- How can I remove a specific item from an array?
- Sort array of objects by string property value
- What is the way of declaring an array in JavaScript?
- jQuery.click() vs onClick
- Remove duplicate values from JS array [duplicate]
- How to loop through an array containing objects and access their properties
- How do I empty an array in JavaScript?
- Remove duplicate values from JS array
- Add swipe left/right to web page, but use default swipe up/down
- Check if checkbox is checked with jQuery
- Angular: mat-form-field must contain a MatFormFieldControl
- How to check if array is empty or does not exist?
- Why is using “for…in” for array iteration a bad idea?
- Change Background color (css property) using Jquery
- Failed to load resource: net::ERR_FILE_NOT_FOUND loading json.js
- Get class name using jQuery
- How to clear the canvas for redrawing
- JavaScript get element by name
- Use images like checkboxes
- Completely disable scrolling of webpage
- How to print elements from array with javascript
- How do I scroll to an element using JavaScript?
- Short circuit Array.forEach like calling break
- display variable image using cookies
- character counter – backspace doesn’t reflect on characters remaining
- Open URL in same window and in same tab
- How to convert selected HTML to Json?
- How to Open New window on every Click
- How to loop through an array containing objects and access their properties
- “.addEventListener is not a function” why does this error occur?
- Convert Array to Object
- Cannot read property ‘getContext’ of null, using canvas
- How to move an element after another element using JS or jquery?
- How to use Javascript to read local text file and read line by line?
- Why is the jquery script not working?
- DOMException: Failed to load because no supported source was found
- Counting the occurrences / frequency of array elements
- Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array
- Partial render in HTML/JavaScript
- How to add onload event to a div element
- Checking for duplicate strings in JavaScript array
- Setting and getting localStorage with jQuery
- Print the contents of a DIV
- Embedding instagram webpage inside an iframe
- Set value to currency in
- Uncaught TypeError: Cannot read property ‘toUpperCase’ of undefined
- HTML Entity Decode
- why angularjs ng-repeat not working
- Scroll to bottom of div?
- Most efficient method to groupby on an array of objects
- Array Mapping in AngularJs
- HTML5 rich-text inside textarea
- How do I check if a cookie exists?
- Highlight a word with jQuery
- How do I refresh a DIV content?
- Get JavaScript object from array of objects by value of property [duplicate]
- jQuery sort elements using data id
- getContext is not a function
- JavaScript code to stop form submission
- How to change the text of a label?
- Change an image with onclick()
- JavaScript – Count Number of Visitor for Website
- Strip HTML from Text JavaScript
- Using “×” word in html changes to ×
- Fire oninput event with jQuery
- Changing the selected option of an HTML Select element
- img onclick call to JavaScript function
- How to scroll to top of page with JavaScript/jQuery?
- Calling a JavaScript function in another js file
- How to embed an autoplaying YouTube video in an iframe?
- JavaScript code not running in HTML5 document
- Cannot read property ‘style’ of undefined — Uncaught Type Error
- Unexpected token < in first line of HTML
- How to make HTML element resizable using pure Javascript?
- How to set “style=display:none;” using jQuery’s attr method?
- WordPress Bootstrap Handburger Menu Wont Open
- Adding JavaScript to a WordPress website
- How to display post content in the block editor
- My Button Default Click Is Not Working In WordPress Using Javascript Code
- Make a script work within a page
- how to let users upload their custom cover image
- Putting custom html/js page into Elementor as it’s own block
- Add Paypal button redirect to a specific page after completing
- Can’t Listen to KeyDown in TInyMCE Iframe (jQuery) and Pass it to Parent HTML FORM
- Making the HTML list to a checkbox tree with the plugin jstree [closed]
- dropdown does not work [closed]
- How do I cycle a JS function in WordPress? [closed]