Back to all resources
localStorage
JSON
data storage

Set localStorage

By Jared Malan
This code snippet demonstrates how to store an array of surfer names into the browser's localStorage. The array surfers contains a list of five famous surfers. The localStorage.setItem method is used to save this array in the localStorage under the key 'surfers'. The array is first converted to a JSON string using JSON.stringify to ensure it can be stored as a string in localStorage.