数组1: [[P01,153425],[P02,3951990],[P03,106658],[P04,4563594],[P05,60198],[P07,326292],[P08,1265],[P09,108293],[ P10,183698],[P11,5084]]来自BigQuery。
ARRAY2: [[P01],[P02],[P03],[P04],[P05],[P06],[P07],[P08],[P09],[P10],[P11]] 使用sheet.getSheetValues(3,1,1,1,1);
从Google工作表列中获取此数组基于此,我应该根据Array1和Array2之间的匹配值更新Google工作表中的列: 例如:[153425,3951990,106658,4563594,60198,326292,1265,108293,183698,5084]
如果值不匹配,相应的值应保持为空。
答案 0 :(得分:0)
将Array1[i][0]
与Array2[j]
循环内的for
进行比较,如果相等,则取Array1[i][1]
for(var i=0; i<Array1.length; i++){
for(var j=0; j<Array2.length; j++){
if(Array1[i][0] == Array2[j]){
//do something
//if it can be equal to only one number, you can break it here
}
}
}
修改强>
然后您应该将Array2[i]
与Array1[j][0]
for(var i=0; i<Array2.length; i++){
var isExist = false;
for(var j=0; j<Array1.length; j++){
if(Array2[i] == Array1[j][0]){
//do something
//if it can be equal to only one number, you can break it here
isExist = true;
}
}
if(!isExist){
//do something if it does not exist
}
}