2

Why does this work:

table.setCell(0,0,[18,12,31]);

and this doesn't

strTime="18:12:31";
time = strTime.split(":");
table.setCell(0,0,time);

the column has been defined by

table.addColumn('timeofday','Time');
Herman
  • 21
  • 1

1 Answers1

1

When you do a

strTime.split(":");

the result is an

Array [ "18", "12", "31" ]

which contains strings, not integers. Yet, the timeofday type requires an array of four numbers:

If the column type is 'timeofday', the value is an array of four numbers: [hour, minute, second, milliseconds].

To obtain an array of Numbers, you could use

strTime.split(":").map(Number)

which applies the Number-function to each string element. This returns a Number object. The map applies it recursively to each element of the array.

serv-inc
  • 35,772
  • 9
  • 166
  • 188