Retrieve all data from LocalStorage (without knowing the key name)

前端 未结 1 1351
余生分开走
余生分开走 2021-02-06 00:42

I\'m looking for a way to get all the information out of localStorage. The trouble I\'m having is I don\'t know what the data will be as it is user generated.

So here w

相关标签:
1条回答
  • 2021-02-06 01:41

    window.localStorage.key is the solution. Example:

    var i = 0,
        oJson = {},
        sKey;
    for (; sKey = window.localStorage.key(i); i++) {
        oJson[sKey] = window.localStorage.getItem(sKey);
    }
    console.log(oJson);
    
    0 讨论(0)
提交回复
热议问题