-5
How do I retrieve items that are this way in localStore
lista-pessoas[{"name":"Hamburguer","adicao":"+carne","data":"2"}]
-5
How do I retrieve items that are this way in localStore
lista-pessoas[{"name":"Hamburguer","adicao":"+carne","data":"2"}]
0
You can use the command:
var value = localStorage.getItem(keyName);
source: https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem
0
To redeem the item from localStorage use the method getaway and how a text has been saved and this represents an object as demonstrated in your question needs to be converted again to an object with JSON.parse(), a complete example follows below with recording, recovery and viewing information in a list:
//dados.
const data = [
{"name":"Hamburguer 1","adicao":"+carne","data":"2"},
{"name":"Hamburguer 2","adicao":"+carne","data":"2"},
{"name":"Hamburguer 3","adicao":"+carne","data":"2"}
];
//gravando o dado no localStorage.
localStorage.setItem('data', JSON.stringify(data));
//recuperando o dado do localStorage.
const textData = localStorage.getItem('data');
const newData = JSON.parse(textData);
//recuperando a tag da sua tela.
var ul = document.getElementById('tul');
//listando a informação.
newData.map(function(data, index) {
const li = document.createElement('li');
li.appendChild(
document.createTextNode(data.name)
)
ul.appendChild(li);
});
great and how I display in html in a div?
I got it, bro! Topppp
Only one question how to save the items for example a link that saves these changes? for example <the name date="BURGER1" value date="5.00">BURGER1</a> <the name date="+MEAT" value date="1.00">+MEAT</a> <the name date="+LETTUCE" value date="1.00">+LETTUCE</a>
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
Add more details to your question so it can be answered. If in doubt, please read the Stackoverflow Survival Guide https://pt.meta.stackoverflow.com/questions/8045/guia-survivor%C3%aancia-do-stack-overflow-em-inglés%C3%aas? cb=1
– Leticia Rosa
I would like to list them for example:
– Felipe
Item: name, name, name
– Felipe
List in a div
– Felipe