Why "null" in array of localStorage?

Why "null" in array of localStorage?

I'm using this code to add values to local storage:

  1. rowSettings[counter] = [value1, value2, value3];
  2. localStorage.setItem("rowSettings", JSON.stringify(rowSettings));
The result in the localStorage is then: [null,[1,0,0],[1,0,0],[1,0,0],[1,0,0]].

So howe come "null" is being added?

In Chome developer tool I get: "Uncaught TypeError: Cannot read property '0' of null".

This happens when retrieving the objects back:

  1. var row =0;
  2. var retrievedObject = JSON.parse(localStorage.getItem('rowSettings'));
  3. //Start each function
  4. for (var i = 0; i < 3; i++) {
  5. alert(retrievedObject[row][i]);
  6. }
  7. row++;
  8. //End each function