How to save JSON data locally (on the machine)?

前端 未结 2 946
后悔当初
后悔当初 2020-12-01 19:30

I am using the following link to create a tree like structure: LINK

This is my code :




    

        
2条回答
  •  心在旅途
    2020-12-01 19:57

    LocalStorage does exactly that.

    Use it like this :

    localStorage.setItem('myCat', 'Tom');
    console.log(localStorage.getItem('myCat')); // Tom
    

    Use can use it to store stringify-ed objects as well :

    var obj = { a : 1, b : 2};
    localStorage.setItem('myObj', JSON.stringify(obj));
    var obj2 = JSON.parse(localStorage.getItem('myObj'));
    

提交回复
热议问题