how can I read multiple keys from localStorage with React?

I am saving several keys in the localStorage with the following line

code

and I want to iterate them to display the products in a cart.
but I can’t get it to show all the keys

const arre = Object.keys(localStorage)

const recorreArray = (arr) => {
  for(let i=0; i <= arr.length; i++){
  console.log(arr[i]);
  }
}

const prueba = recorreArray(arre)
  

  const stringifiedProducts = localStorage.getItem(arre)
  const products = JSON.parse(stringifiedProducts) 

21 thoughts on “how can I read multiple keys from localStorage with React?”

  1. 205901 327257I like the valuable information you give within your articles. Ill bookmark your weblog and check once again here regularly. Im quite certain Ill learn a lot of new stuff right here! Good luck for the next! 421644

    Reply

Leave a Comment