How to retrieve all localStorage items without knowing the keys in advance?

前端 未结 8 1472
天涯浪人
天涯浪人 2020-12-04 13:59

I want to show all of the keys and storage written before. My code is below. I created a function (allStorage) but it doesn\'t work. How can I do this?

           


        
相关标签:
8条回答
  • 2020-12-04 14:53

    These are all bulky or downright incorrect.

    The Correct Answer is:
    JSON.parse(JSON.stringify(localStorage))

    0 讨论(0)
  • 2020-12-04 14:56

    The easiest way would be to use:

    return JSON.stringify(localStorage);
    
    0 讨论(0)
提交回复
热议问题