0

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Right on! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.