+ 8
How can I add two arrays?
How can I add two arrays? https://code.sololearn.com/WDSv8v27I8Ry/?ref=app (Plus + wont work)
7 Respuestas
+ 6
Its interesting thing, that such adding arrays causes adding commas in array
+ 4
arr = arr1.concat(arr2);
+ 4
You can add the elements of arrays having the same index
...
+ 3
You can simply use loop to add two arrays as
var arr1= [1, 3];
var arr2 = [2, 4];
var set= [];
for(var i= 0; i<arr1.length; i++){
set[i]= arr1[i] + arr2[i];
console.log(set[i]);
}
+ 1
var arr1=[1,3] //arr1
var arr2=[2,4] //arr2
arr1=arr1.join("") //change arr1 to String without the qoma
arr2=arr2.join("") // Same arr1
arr1=arr1.concat(arr2) //to gather them as string
const [...set]=arr1 //to change it to string again
alert(set) //see
set.forEach((e,i)=>{
set[i]=Number(e) //to change each element in set to number
})
console.log(set.reduce((a,b)=>a+b)) //for addition them one by one
+ 1
The description in the comments