Below is the code that I came up with to import the values of a key in localStorage and supply each value the key holds into a function. Being that I'm very new to JavaScript, I was wondering if there's a better way to do what I did below and still provide the same outcome ?
Code :
function importStorage() {
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i); // This references the key
const values = localStorage.getItem(key) // This pulls the values associated
const newValues = values.slice(2, -2) // This removes this ( and this )
const finalValues = newValues.split("', '") // This then splits the string
newBill(finalValues[0], finalValues[1], finalValues[2])
}
}
Is there a better way to achieve it ?