Creating the storage object
Now, we will create the storage object. Find the storage.js
file that we created, which should be empty. We will use the storage
object to save and retrieve the application data.
Note
Please pay attention to trailing commas when adding methods to this JavaScript object. Every method should be followed by a comma. The last method is optional.
First, we will look at each individual method and what each one does. Then we will create the entire object.
The storage methods and properties
There are two properties we created in the storage
object that are specific for helping it to operate.
lastStoredId
The first property is the
lastStoredId
property:
lastStoredId: localStorage.getItem("lastStoredId")? localStorage.getItem("lastStoredId"):0,
This property retains the ID of the last entered item inside localStorage
. Upon initial loading of the page, this property checks the localStorage
item lastStoredId
for a value. If it has one, that value is assigned to the storage
object...