adding objects to array in localStorage

后端 未结 5 1812
轮回少年
轮回少年 2021-01-11 10:44

Ok, I\'ve tried to follow examples here, I know there might be a few different ways of adding objects to an array in localstorage and not overwriting it but I\'m failing to

5条回答
  •  伪装坚强ぢ
    2021-01-11 11:29

    const object = {
    name: 'ayyan',
    age: 29,
    number: 03070084689,
    };
    const arr = JSON.parse(localstorage.getItem('key_name')) || [];
    arr.push(object);
    localstorage.setitem(json.strigify('key_name', arr);

提交回复
热议问题