If you loves working on Google suits, i am sure you work on Google Apps script which is based on JavaScript. While working on Google Apps Script (GAS) you have came across situation where you have two list or array and you want to loop over each item one by one. Here in this post we will see how to Loop over two list or array in Google Apps Script simultaneously.
Basically a list is a collection of any number of items of similar or different data types. You have worked on the list in all other programming languages like python, C, C++ etc. basic syntax of list/array is as shown below:
Code to see how to Loop over two list or array in GAS:
function Loop() { var Names = ['John','Andrew','Jacob'] var Dept = ['IT','Analytics','Admin'] for (i=0; i < Names.length; i++){ Logger.log(Names[i] + ' works in '+ Dept[i] + ' Department ') } }
Basically what we are trying to do in the above code is that we have two list one is name of the employee and second the department they work in a same order. So we want to loop over both the list or array and print the name along with department.
The above code will show the output as below:
John works in IT Department
Andrew works in Analytics Department
Jacob works in Admin Department
To get more detailed knowledge about Google Apps Script, you can check the official website. Also if you want to explore more codes/posts related to Google Apps Script on our website, then you can find it here.
If you have any questions or if you need any help please get in touch with me using the comment section below.
Leave a Reply