Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to push this array into an 2D array using GAS? without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
How can I have ar2
pushed into ar1
so as to have them like the Expected Output below?
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
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:
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.
Answer
To concat the array you can use concat()
method
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
We are here to answer your question about How to push this array into an 2D array using GAS? - If you find the proper solution, please don't forgot to share this with your team members.