>"PM_ABCD","long string is here" >"PM_1233", "another long string here" >"ABC", "Another long string" >"PM_G134555","long string" >>
String.prototype.startsWith = function(startText) { return this.slice(0, startText.length) == startText; }; var pmKeys = new Array(); for (var x = 1; x < localStorage.length; x++) { var s = localStorage.key(x); if (s.startsWith("PM_")) { pmKeys.push(s); } }But it may be better to store all those items as an array of objects under one key.e.g:
var toStore = [ { Key: "PM_ABCD", Value: "long string is here" }, { Key: "PM_1233", Value: "another long string here" }, { Key: "ABC", Value: "Another long string here" }, { Key: "PM_G134555", Value: "long string" } ]; localStorage.setItem("MyList", JSON.stringify(toStore));Then you can pull them back into an array which is easier to manipulate:
var myList = JSON.parse(localStorage.getItem("MyList")); var pmKeys = new Array(); myList.forEach(function(item) { if (item.Key.slice(0, 3) == "PM_") { pmKeys.push(item.Key); } });I usually pull any stuff that I'm likely to need from localStorage into memory when the page loads.