I don’t know if it was a typo here, but the object window
that’s all
lower case (you capitalized the "W", which will result in
error).
You don’t need to use JSON parse, just put it on localStorage
the direct array it is already saved in string form.
That is, when using:
var pessoa = ["Bonito","Alto","Magro"];
window.localStorage.setItem('pessoa', pessoa);
The value of localStorage
will be the array in string form:
"Bonito","Alto","Magro"
And to recover you use .getItem()
and .split(",")
to convert to array again (if there is no comma in the middle of the words in the array):
var pessoaAntiga = window.localStorage.getItem('pessoa').split(",");
This method should be used carefully, if any string in the array contains comma, the
split
will not return the expected value. And just to be explicit, it is not thatWindow
be wrong, butWindow
refers to the type (constructor function), equatorwindow
the value (object)– Costamilam
True friend. I will reevaluate the answer. Obg!
– Sam