Gabriele Ferro Home

Store an Array in HTML5 localStorage

Few days ago, I tried several approaches to code my shopping cart.

None of them worked.

So I went back to freeCodeCamp to fill my gaps and to review the advanced JavaScript concepts.

And then, I coded (again) the JavaScript file that simulate our cart but this time I tried to store an array of objects using a class.

Surprisingly... It did not work.

Yesterday, late at night, I "cheated" and I asked a solution to my personal Aristotele version 2.0 :


The answer was OF COURSE given on stack overflow:

"Storing Objects in HTML5 localStorage"

Asked 10 years, 7 months ago - Active 24 days ago - Viewed 1.1m times"

So I am not alone anymore. Scrolling down the page my savior: Andy Lorenz gave me the code I was looking for since one week.

Day34: 28 August 2020

**Today’s Progress:**

Started my Pomodoro and I coded this few magical lines and TA-DA.

It works.

He uses a different approach, and I didn't think it was possible:

using the localStorage interface, he adds a function to its prototype.

I continued to code the entire evening, and before dinner, I had a video call with my OpenClassRooms mentor. He suggested to me to look at the fetch method (so I can convert my XMLHttpRequest into a chain of promises) and the template HTML tag. He showed to me how to code the cart using a class and how to use the bind method. I ignored how the bind method was important and so I asked to Google again:

I discovered and found this article with examples of losing this.

Lastly, I have read this article published by Quincy Larson so I created my account on codingame.


I am thrilled to announce that I have finally finished writing my first book:

**Link to tweet:**

[twitter-follow screen_name='20Gabriele20']

July 2024


Gabriele Ferro Home
Copyright © Ferro Gabriele. All rights reserved.