What is the best way to iterate a multidivisional array using forEach JavaScript Google script?
I came up with this.
values.forEach(function(row){
values[0].forEach(function(_,col){
console.log(row[col])
});
});
While it works I have a feeling there is a better way to write it
2
Answers
You can directly call
forEach
on the inner array:You can iterate directly over
row
:Alternatively, you can use arrow functions and make it into a one-liner:
You could also use a
for..of
loop: