Created
March 22, 2020 09:37
-
-
Save meisterk/7a1044c08198d17cc0e1fe8ace7e0d22 to your computer and use it in GitHub Desktop.
Read an write to localstorage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// READ FROM LOCALSTORAGE | |
if(localStorage.getItem('data')){ | |
let dataString = localStorage.getItem('data'); | |
dataArray = JSON.parse(dataString); | |
}else{ | |
dataArray = []; | |
} | |
// WRITE TO LOCALSTORAGE | |
let dataString = JSON.stringify(dataArray); | |
localStorage.setItem('data', dataString); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment