[英]How to push this array into an 2D array using GAS?
How can I have ar2
pushed into ar1
so as to have them like the Expected Output below?我怎样才能将ar2
推入ar1
以便让它们像下面的预期 Output 一样?
ar1 =
[
[true,160,"Blusa Crepe Barcelona manga curta",2,"","","",100],
[true,161,"Blusa Crepe Barcelona manga curta",1,"","","",100]
]
ar2 = ["Concluído",1000]
Expected Output预计 Output
result = [
[true,160,"Blusa Crepe Barcelona manga curta",2,"","","",100,"Concluído",1000],
[true,161,"Blusa Crepe Barcelona manga curta",1,"","","",100,"Concluído",1000]
]
I've tried doing it using a douple for loop
, but I haven't been able to make it right, as it pushes ar2
as another array in the outer array:我尝试过使用双重for loop
来做,但我无法做到这一点,因为它将ar2
作为外部数组中的另一个数组推送:
let output= [];
for (let i = 0; i < ar1.length; i++){
for (let j = 0; j < ar1[i].length; j++){
output.push(ar1[j],ar2)
}
}
Appreaciate your help.感谢您的帮助。
To concat the array you can use concat()
method要连接数组,您可以使用concat()
方法
ar1 = [ [true,160,"Blusa Crepe Barcelona manga curta",2,"","","",100], [true,161,"Blusa Crepe Barcelona manga curta",1,"","","",100] ] ar2 = ["Concluído",1000] for(let i = 0; i<ar1.length;i++){ ar1[i] = ar1[i].concat(ar2) } console.log(ar1)
For more info on concat()
please refer here有关concat()
的更多信息,请参阅此处
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.