In my Google Apps Script project, I am facing a challenge while trying to insert an array into another array. The scenario involves extracting data from a spreadsheet, which is essentially an array of arrays. I then have to compare this data with another array and store the corresponding values in a new array. The catch is that the new array needs to maintain the same structure as the original one. However, I'm struggling to achieve this desired result. My attempts to 'push' the matched array elements either result in a single large array or multiple smaller arrays that don't align with the original structure. Furthermore, when I tried using an index based on the loop of the original array, I encountered a 'TypeError'.
/*
Step 1 - Read All Data Into An Array
*/
//Gets Client Data For Each Firm
mysheet = ss.getSheetByName(sheetNames[1]); //Adjusted worksheet
ss.setActiveSheet(mysheet);
arrInput = ss.getRangeByName(rngNameRawClientType).getValues();
//Gets Client Classifcation and Score Data
mysheet = ss.getSheetByName(sheetNames[2]); //Data Validation worksheet
ss.setActiveSheet(mysheet);
arrClassification = ss.getRangeByName(rngNameClient).getValues();
/*
Step 2 - Perform Calculations on the Data
*/
//Iterate Through Raw Data Input Array (Rows)
for(var r = 0; r < arrInput.length; r++) {
//Iterate Through Column of Each Row
for(var c = 0; c < arrInput[r].length; c++) {
var strClientType = arrInput[r][c];
//Compare To Classification Array - Return Corresponding Score
var matchScores = [];
for(var z = 0; z < arrClassification.length-1; z++) {
if(arrClassification[z][0] === strClientType) {
//Add Score to Scores Array
matchScores.push(arrClassification[z][1]);
}
}
}
scores.push(matchScores);