I need to check if there is any key in localStorage This code did not work
if (localStorage.user === undefined) {
alert('There is no key!');
}
I need to check if there is any key in localStorage This code did not work
if (localStorage.user === undefined) {
alert('There is no key!');
}
if (Object.keys(localStorage).length === 0) {
alert('There is no key!');
}
You need to use getItem
if (localStorage.getItem("user") === null) {
alert('Não há chave!');
}
EDIT You can check if the localstorage is empty by
if (localStorage.length == 0)