0
for(i = 0; i < data.length; i++) {
    timesheets.i =  { name, day, month, date, year, time };
}

When I run this code, it just overwrites the values for timesheets as it loops.

How can I name the different objects within timesheets using the variable i?

edit:

The first comment helped a ton. But when I try and create different object using

timesheets[name] = { name, day, month, date, year, time };

it overwrites the values instead of adding an additional object. When I try and use

timesheets[name] += { name, day, month, date, year, time };

It console logs as

{
  'Pres Trump': 'undefined[object Object][object Object]',
  'Pres Obama': 'undefined[object Object][object Object]'
}

What could I be doing wrong?

edit:

fixed with

if(timesheets[name] == undefined){
                timesheets[name] = [ dateOutput, time ]
            }else{
                timesheets[name] +=  [ dateOutput, time ];
            }

0 Answers0