修改 google apps 脚本中的列表元素

Modify the list elements in google apps script

我有 2 个列表如下:

list1 = [01-0160306, 01-0160302]
list2 = [[01-0160299, null, 3496.0, 1.0, null], [01-0160302, null, 18.0, 1.0, null], [01-0160306, null, 18.0, 1.0, null]]

如果 list1 中有元素,则需要检索 list2 中的相应数组,并将最后一个元素“null”替换为“Yes”。结果需要推回 list2。

因此,结果必须是

list2 = [[01-0160299, null, 3496.0, 1.0, null], [01-0160302, null, 18.0, 1.0, Yes], [01-0160306, null, 18.0, 1.0, Yes]]

我尝试遍历 list1 数组,然后遍历 list2 以获取它的第一个元素。但不确定如何检索这些行,修改 并将其推回 list2。

if(list1.length > 0){
 for(i=0;i<list1.length;i++){
   for (j=0;j<list2.length;j++){
     if(list2[j][0] == i){ //if there is a match
      //Not sure how to modify and push it back to the list2
     }
  }
}}

我正在学习 Google Apps 脚本,任何 suggestions/leads 都会有很大帮助

只需将新值'Yes'写入所需的数组元素

...
if(list2[j][0] == i){ //if there is a match
      list2[j][4] = 'Yes'   //Not sure how to modify and push it back to the list2
     }
...

JavaScript Array Methods