Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Length of two dimensional array in Javascript/Google Apps Script

I have a two dimensional array in a Google apps script

data = [[1, 2], [3, 4]];

Trying to get the length of data returns "Undefined". Why is that?

Logger.log(data.length) // Outputs "Undefined"

Update (full code):

data = sheet.getSheetValues(1, 1, 10, 2);
Logger.log("readSpreadSheet");
Logger.log(data);
Logger.log(data.length);

Log:

[14-02-10 15:05:05:592 CET] readSpreadSheet
[14-02-10 15:05:05:592 CET] [[tt0062622, 10.0], [tt0066921, 10.0], [tt0094721, 8.0], [tt0445934, 10.0], [tt0784972, 7.0], [tt1136608, 1.0], [tt0119116, 10.0],     [tt1195478, 7.0], [tt2234155, 1.0], [tt1675434, 9.0]]
[14-02-10 15:05:05:592 CET] undefined
like image 786
ihatetoregister Avatar asked Feb 10 '14 14:02

ihatetoregister


People also ask

What is the size of a 2D array?

The length of a 2D array is the number of rows it has. The row index runs from 0 to length-1. Each row of a 2D array can have a different number of cells, so each row has its own length : uneven[0] refers to row 0 of the array, uneven[1] refers to row 1, and so on.

How do I create an array in Google script?

getNumRows(); //var values = rows. getValues(); var Names = sheet. getRange("A2:A7"); var Name = new Array(6); var Name_cell = Names. getCell(1, 1); var Name[0] = Name_cell.

How do you find the length of a 3D array?

To get the size of a 3D array in C#, use the GetLength() method with parameter as the index of the dimensions.


1 Answers

You made a typo in your code... you wrote lenght instead of length

code :

data = sheet.getSheetValues(1, 1, 10, 2);
Logger.log("readSpreadSheet");
Logger.log(data);
Logger.log(data.length);

log:

data.length = 10
like image 79
Serge insas Avatar answered Nov 10 '22 07:11

Serge insas