(Just so you know, I really appreciate your help as I navigate through teaching myself).
I'm currently working on recreating an array that was previously parsed from session storage.
var entries = JSON.parse(sessionStorage.getItem('entries'));
console.log(entries);
var stDrivArray = JSON.parse(sessionStorage.getItem('entrynames')); //retrieve from storage
var stDrivArray2 = $.makeArray(stDrivArray); //convert into an array format, but the entries are named as "object". They should be named "Driver"
//here is my attempt to rename them as Drivers
for(var i=0; i<stDrivArray2.length; i++){
console.log(stDrivArray2[i]);
var draw2=stDrivArray2[i].draw;
var name2=stDrivArray2[i].name;
var name3 = "."+"driver"+stDrivArray2[i].draw;
Driver[name3] = new Driver(draw2, name2);
console.log(Driver[name3]);
DrivArray[DrivArray.length]=Driver[name3];
};
console.log(DrivArray);
An interesting dilemma: When I display Driver[name3]
in console, it shows the correct output. For example:
Driver {draw: "5", name: "David Dubczak"}
I am attempting to add each object to the DrivArray
, but the result when I print out DrivArray
is this:
0: Driver
draw: undefined
name: undefined
However, there is indeed one object for each driver within the script! It's just that the values are undefined. It's puzzling because the object is being created correctly, but for some reason the values are not assigned properly to the keys in the array (I hope I'm using the right terminology).
What confuses me more is that I am using the same method to add the same object to the same array on a different page (hence the need to store and retrieve from session storage) and it's working flawlessly.
Any insights on this?
Once again, thank you for your help.