+ 8

How can I add two arrays?

How can I add two arrays? https://code.sololearn.com/WDSv8v27I8Ry/?ref=app (Plus + wont work)

30th Apr 2019, 10:34 AM
Sławek J.
7 Réponses
+ 6
Its interesting thing, that such adding arrays causes adding commas in array
10th May 2019, 4:52 PM
Sławek J.
+ 4
arr = arr1.concat(arr2);
30th Apr 2019, 11:15 AM
Solo
Solo - avatar
+ 4
You can add the elements of arrays having the same index ...
1st May 2019, 4:33 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 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]); }
30th Apr 2019, 11:11 AM
Prabhat Kumar Singh
Prabhat Kumar Singh - avatar
6th May 2019, 9:20 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
+ 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
6th May 2019, 9:20 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
+ 1
The description in the comments
6th May 2019, 9:20 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar