I am trying to hide my div if there is no a localStorage key value.
With the line below I achieved only to hide a div when localStorage key completely deleted but need to do the same if localStorage key hasn't got any value at all just [].
window.localStorage.getItem('items') === null
How would it be performed?
How about simply:
An example of how it could be useful:
Here the script will check if the localStorage name does not exist, and if it doesn't, it will create it with the default value.
And if you want it to act when it does exist, you can add an else after the if block to continue, or remove the '!' from the if block condition.
You can add required conditions using the
OR
operator||
If you have to check for
undefined
somewhere as well you can change=== null
to== null
or expand with an extra condition like thisEDIT: Here is what you can do to get the array directly