Append data to localStorage object

后端 未结 4 709
夕颜
夕颜 2021-02-10 11:08

I\'m trying, unsuccessfully, to add a new object to a current localStorage object. Instead of, at the end, having two sets of data in localStorage, I get the last one. Any insig

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-10 11:32

    According to MDN The Object.assign() method only copies enumerable and own properties from a source object to a target object

    in your case: var stored = JSON.parse(retrievedObject); return array, you can just push new object to array: stored.push(newStudent2); and when set stored to localStorage.

提交回复
热议问题