Read and view local storage data from another page Javascript

Hello everyone, on my study project I want the localstorage data to appear on my new page (on my cart), I have created my html page. I don’t understand the syntax, if I have to put a setItem then getItem, only getItem? I haven’t finished completing the cart.js page

const params = new URLSearchParams(;
const id = params.get('id');

const optionLenses = document.getElementById('optionLenses');
let addCart = document.querySelector('.add-card');

  .then(response => response.json())

  .then(data => {
 for (let lense of data.lenses) {produit----------
      optionLenses.innerHTML += `<option value="${lense}">${lense}</option>`;

    let product = {
      price: data.price,
      lense: optionLenses.value,

    addCart.addEventListener('click', () => {

      localStorage.setItem(data._id, JSON.stringify(product));
      document.querySelector('.cart span').textContent = localStorage.length;


  .catch(error => console.log(error))

If you can give me any leads but no answers.

Hi @devastud

I am struggling to understand your question or what exactly it is your are trying to do. But if you want to access the local storage data, then you will have to use the getItem method.

Yes that’s exactly what I want .
On my first page, I set the data in localStorage with setItem.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.