Thanks you Chad for his solution, however it now appears to clear values from the array, here is a foreach on the console log which shows you my situation (followed by the updated code for the update function):
timer.html:60 ------------------------------------
timer.html:57 0
timer.html:58 undefined
timer.html:57 1
timer.html:58 1.910
2timer.html:60 ------------------------------------
timer.html:57 0
timer.html:58 undefined
timer.html:57 1
timer.html:58 undefined
timer.html:57 2
timer.html:58 1.727
2timer.html:60 ------------------------------------
timer.html:57 0
timer.html:58 undefined
timer.html:57 1
timer.html:58 undefined
timer.html:57 2
timer.html:58 undefined
timer.html:57 3
timer.html:58 0.690
timer.html:60 ------------------------------------
=============================================
function updateLap(kartId){
if (isNaN(driverLapNumber[kartId])) {
//IF LAP NOT SET THEN THE KART ID NEEDS TO BE SET AS 0 AS IT IS THE START OF THE RACE
window.driverLapNumber[kartId] = 0;
}
//ADD ONE LAP TO THE KART ID
driverLapNumber[kartId]++;
//ADD LAP TIME FOR CURRENT LAP NUMBER
driverLapTimes[kartId] = [];
driverLapTimes[kartId][driverLapNumber[kartId]] = window.lapTime;
$.each(driverLapTimes , function( index, obj ) {
$.each(obj, function( key, value ) {
console.log(key);
console.log(value);
});
console.log("------------------------------------");
});
$(".lapTimes").prepend("kartId: "+kartId+" - "+window.lapTime+"<br>");
}
I suppose I can blame PHP for this as it would be possible with the way I am writing it currently, I need assistance in correcting this please.
Everything is fine except for the SECOND key on the driverLapTimes array, I want it to output something like:
driverLapNumber[999][1] = 6.666;
driverLapNumber[999][2] = 6.666;
driverLapNumber[999][3] = 6.666;
driverLapNumber[999][4] = 6.666;
But the 1,2,3,4 keys are coming up with the following console error:
Uncaught TypeError: Cannot set property '1' of undefined
The function code:
function updateLap(kartId){
if (isNaN(driverLapNumber[kartId])) {
window.driverLapNumber[kartId] = 0;
}
//ADD ONE LAP TO THE KART ID
driverLapNumber[kartId]++;
//ADD LAP TIME FOR CURRENT LAP NUMBER
driverLapTimes[kartId][driverLapNumber[kartId]] = window.lapTime;
}