Declaring a multi-dimensional (2D) array in Google Apps Script

Robert Merrill
1 min readApr 13, 2020

--

I’ve been looking all over for a way to just make a simple multidimensional array in Google App Script. The other answers all start with pulling data from sheets, but that’s not my case.

The solution is to make an array and declare a length, then loop through the array and set each value to an array of 2 or however many dimensions you want, then set each dimension value as you would.

Sample Code: To setup an array of campusNames with campusName[0][0] = the name of the campus and campusName[0][1] = the school’s URL

//

var campusNames = new Array(13);

for(i=0; i<campusNames.length; i++)
{
campusNames[i] = new Array(2);
}

campusNames[0][0] = “Berkeley”;
campusNames[0][1] = “https://www.berkeley.edu/”;

//

--

--

Robert Merrill

Tech recruiter turned tech founder 🚀 Helps you hire smarter, faster, and better. Let’s get to work. ConnectedWell.com; Twitter: @AskRobMerrill