How do I count the number of rows of an array?

Sorry for the trivial question

how do you count the number of lines of an arrey (which I created with this code)?
var perstaz = fEmissioneRicevuta.getRange (16,2,11,2) .getValues ​​();

and how is it assigned to a variable (I tried that)?
var x = perstaz.lastIndexOf

As a result I only get a -1.0

.length .... ?

Yesss! :slight_smile:
Length selects all lines. If I want to capture only the lines that contain a value, do I have to do a 'for' loop or is there a suitable command?

Which programming language are you working in?

app script google sheet

Yes, a for each loop, testing for a value in each item is the way to go. for example:

var arr = [];
var data = sh.getRange(16,2,11,2).getValues();
for (var i=0; i<data.length;i++) {
if ( data[i] != "" ) {
arr.push(data[i]);
}
}

I am trying to solve the problem by looking for videos etc ... but maybe I am creating confusion.

This code
var performance = fEmissioneRicevuta.getRange (16,2,11,2) .getValues ​​();

returns data from the first column only. I cannot read and assign data from the second column.

Also I keep getting 11 lines as a result of the for loop even though several lines are blank

To populate the ary this code is sufficient:
var performance = fEmissioneRicevuta.getRange (16,2,11,5) .getValues ​​();

I couldn't see the second value because I was counting the adjacent cells (2) but in reality the first cell was joined with three other cells, so in reality the ary is made up of 5 columns.

Fixed with a lot of sweat on the brow. But I'm happy because I'm learning and knowing that I can count on this forum that helps me to walk in the right direction makes everything more stimulating

In fairness I had to write:
if (persentaz [riga] [0]! = "")

To include only written lines in the arrey and exclude empty ones

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.