const data = async () => {
const response = await fetch("https://jsonplaceholder.typicode.com/users");
const data = await response.json();
console.log(data);
};
I have been trying to access data here, and I have searched the net, and as a beginner, the answers I'm getting are too confusing, so please make it simple for me. Thank you.
When you get your data, you can store it in localStorage. Like this:
localStorage.setItem("someData", data);
and after that, you can use it anywhere when you get it from localStorage with this:
const someData = localStorage.getItem("someData");
And if you want to clear this data, you can use this:
localStorage.removeItem("someData);
EDIT: localStorage only supports strings! For arrays in JSON format, You can use JSON.stringify() and JSON.parse().
var data= [];
data[0] = prompt("New data?");
localStorage.setItem("someData", JSON.stringify(data));
And when u get it, you can use this one:
//...
var someData= JSON.parse(localStorage.getItem("someData"))