#🚀︱start-here
In my project, I would like to store data to the localStorage.
I would like the data to be stored as array of objects.
Initially, my data is empty array, like this:
data = [];
Then I am putting an object inside it (using push() method), like this:
localStorage.setItem("scores", this.data.push({name:"someName", score: 4}))
and I am getting the following:
[ { name: "someName", score: 4 } [
Until now everytghing is OK.
Then I want to push another object to the data property.
I am doing the following:
localStorage.setItem("scores", this.data.push({name:"anotherName", score: 1})).
Now instead array with two objects, I am getting array with one object (only the last one).
I am geting this:
[ { name: "anotherName", score: 1 } ]
I tryed to use spread operator to add second object to the data array, but I am still getting the same result.
I should get array with two objects, but I am getting array with one object. Why?