Loops 修改google应用程序脚本中的列表元素
我有以下两个列表:Loops 修改google应用程序脚本中的列表元素,loops,google-apps-script,comparison,Loops,Google Apps Script,Comparison,我有以下两个列表: 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]] 如果列表1中有元素,则需要检索列表2中相应的数组,最后一个元素“null”必须替换为“Yes”。结果需要推回到列表2 if(list1.length > 0){
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]]
如果列表1中有元素,则需要检索列表2中相应的数组,最后一个元素“null”必须替换为“Yes”。结果需要推回到列表2
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
}
}
}}
因此,结果必须是
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上循环以获得它的第一个元素。但不确定如何检索这些行,请修改
并将其推回到列表2
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
}
}
}}
if(list1.length>0){
对于(i=0;i只需在所需数组元素中写入新值“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
}
...
只需在所需数组元素中写入新值'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
}
...