I have following types of keys in my localStorage,
Key: Designer-96, Value: true
Key: Designer-76, Value: true
On Page_Load() I want to identify if localStorage contains any keys that start with Designer word, if that's the case then I want to execute certain logic.
Is it possible to iterate through the keys of localStorage in JavaScript and find part of the matching key?
You can get all keys of localStorge using
Object.keys(localStorage)
and you can then use some to check for the existence of a key starts with Designer
const ls = localStorage;
ls.setItem("Designer-96", true);
ls.setItem("Designer-76", true);
const keys = Object.keys(ls);
if (keys.some((k) => k.startsWith("Designer"))) console.log("Key is present");
else console.log("Key is not present");