Can someone help with syntax on returning any specific column of an array in Google script / Java Script.
Array
01 02 03 04 05
06 07 08 09 10
11 12 13 14 15
2nd row of array...
Browser.msgBox(values[1]);
06 07 08 09 10
what's the syntax for returning values of 2nd column?
Are there simpler way without the for loop path, reason being I have a 7k row by 28 column array and trying to mak it more efficient via better call methods.
Browser.msgBox(values[x][y]);
Where x
is the row, y
is the column.
I don't know why you are getting the second row via 2
though. Arrays "zero-indexed". They start with 0
. You should be getting the third row with 2
.
You can't get the values of second column directly, you will have to aggregate them manually.
Ex:
function getColumn(array, column){
var result = [];
for(var i = 0; i< array.length; i++){
result.push(array[i][column]);
}
return result;
}
Then
var column2 = getColumn(myArray, 1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.