WeirdGeek

Data Science | Machine Learning | Automation

  • Data Analytics
  • Python
  • Data Science
  • Google Apps Script
  • Machine Learning
  • Artificial Intelligence
  • SQL Server

11/11/2019 By WeirdGeek Leave a Comment

Loop over two list or array in Google Apps Script

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.

Loop over two list/array in Google Apps Script

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.

Related posts:

  1. Google Apps Script to search a string in Google Sheet [Part II]
  2. Unzip files using Google Apps Script on Google Drive
  3. Import CSV file data to Google Spreadsheet using Google Apps Script
  4. Google Apps Script Code to find the days of the week

Filed Under: Data Science Tagged With: Automation, code, Google, Google Apps Script, Script

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Subscribe to my Blog !!

Enter your email below to subscribe my blog and get the latest post right in your inbox.

  • Home
  • Terms
  • Privacy
  • Contact Us

Copyright © 2025 · WeirdGeek · All trademarks mentioned are the property of their respective owners.