localStorage saves a string
then to save you must do the following:
localStorage.setItem('dados_usuario', JSON.stringify(dados_usuario ));
And to read:
const dados_usuario = JSON.parse(localStorage.getItem('dados_usuario'));
You can test with the following code:
const gravar = { idCmos: "83903", codigoPlang: "302432", tipoPlang: "39ieej", nome: "TaskControl" };
// Grava a variável no localStorage
localStorage.setItem('dados_usuario', JSON.stringify(gravar));
// Lê do localStorage
const lido = JSON.parse(localStorage.getItem('dados_usuario'));
console.log(lido.nome);
Storage
The Web Storage API interface provides access to session storage or local storage for a specific domain, allowing you, for example, to add, modify or delete stored data items.
localStorage
The localStorage property allows you to access a local Storage object. A localStorage
is similar to sessionStorage
. The only difference is that while the data stored on localStorage
do not expire, the data in sessionStorage has its data cleared when the page session expires - that is, when the page (tab or window) is closed.
sessionStorage
The sessionStorage property allows you to access a Session Storage object. A sessionStorage
is similar to localStorage
, the only difference is that while the data stored in localStorage
do not expire, data in the sessionStorage
You have your data cleared at the end of the page session. The page session lasts while the browser is open and stays in the page reload. Opening the page in a new tab or window will generate a new session, which differentiates how cookies work.
JSON.parse
The method JSON.parse()
parses a JSON string, constructing the value or an object JavaScript
described by string
. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
JSON.stringify
The method JSON.stringify()
converts values into JavaScript
for a String
JSON
. These values can be replaced by specifying the function replacer
, or including only specific properties, when the replacer
is specified.
But you want to read the key or the value for a key?
– LipESprY
The value of the key
– Robson Freitas
I corrected the question
– Robson Freitas
In that case, you will have to post the JSON. Run a
console.log(dados_usuario)
and put the result in your question.– LipESprY
I’ve uploaded the console output.
– Robson Freitas
Try the answer hint below and remember to fix "the key":
dados_usuario.nomeEntidade
fordados_usuario.nome
. ;d– LipESprY