Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

function delete localstorage key with prefix

var arr = []; // Array to hold the keys
// Iterate over localStorage and insert the keys that meet the condition into arr
for (var i = 0; i < localStorage.length; i++){
    if (localStorage.key(i).substring(0,3) == 'TM_') {
        arr.push(localStorage.key(i));
    }
}

// Iterate over arr and remove the items by key
for (var i = 0; i < arr.length; i++) {
    localStorage.removeItem(arr[i]);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #function #delete #localstorage #key #prefix
ADD COMMENT
Topic
Name
7+6 =