Hey there! I'm currently working on a project where I need to extract values from the 1st and 2nd rows and store them in an object. Here's my current code:
function getTime(){
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var d = {}
var quantity = ss.getRange(2,4,2,24).getDisplayValues();
var fruit = ss.getRange(3,4,3,24).getValues();
var quantityFiltered = quantity[0].filter(item => item);
var fruitFiltered = fruit[0].filter(item => item);
for (let i = 0; i < quantity.length; i++) {
for (let j = 0; j < fruit.length; i++){
d[quantity[i]] = fruit[j]
}
}
However, I'm not satisfied with this approach and the for loop seems to be stuck. I want to automate this process more to minimize errors in the data.
What I really need is an object structured like this:
{
"Apple": 23,
"Banana" 25,
"Apple": 30,
"Grapes": "No value",
"Apple": 31
}
Do you think it's possible to write a code using an approach similar to the following example?
dic = {}
for quantity,fruit in zip(ss.getRange(2,4,2,24).getDisplayValues(), ss.getRange(3,4,3,24).getValues()):
dic[fruit] = key
This pythonic approach works well, but I need to convert it into JavaScript for app script purposes.