I use SessionStorage to store information about selected items to pack. So I have a number of keys like (pack01, pack02, pack07, pack22, etc), but there are also other keys in the SessionStorage too.
I would like to write a function to iterate through all keys that the name starts with (pack) - only these ones.
Sample objects in SessionStorage:
pack01: [{"pack_items":1,"pack_name":"testname1"}]
pack02: [{"pack_items":2,"pack_name":"testname2"}]
test: test
Code so far:
for (let i = 0; i < sessionStorage.length; i++) {
const key = sessionStorage.key(i);
if(sessionStorage[key].hasOwnProperty('pack_items')){
console.log(sessionStorage[key]['pack_items']);
}
else {
console.log('FALSE');
}
console.log(`${key}: ${sessionStorage.getItem(key)}`);
}
Any advice? Thank you