Local Storage JavaScript
1. Save Data: Use localStorage.setItem(key, value) to store data in LocalStorage. In the example, we store the username 'JohnDoe' with the key 'username'.
2. Retrieve Data: Employ localStorage.getItem(key) to retrieve data from LocalStorage. Here, we retrieve the username using the key 'username' and log it to the console.
3. Update Data: To update existing data in LocalStorage, you can use localStorage.setItem(key, updatedValue). In this case, we update the username to 'JaneDoe'.
4. Remove Data: The method localStorage.removeItem(key) allows you to remove a specific item from LocalStorage. Here, we remove the username from LocalStorage using the key 'username'.
Comments
Post a Comment