0
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.

  • 1
    In the interest of content quality, duplicative questions are not permitted here. Please research your inquiry before posting here in accordance with [ask]. This is a duplicate of [How to Store Objects in HTML5 localStorage?](https://stackoverflow.com/questions/2010892/how-to-store-objects-in-html5-localstorage) – esqew Feb 01 '22 at 14:04

1 Answers1

-2

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"))
IVANOFF
  • 581
  • 5
  • 7