+ 2

Javascript - Adding arrays

I understand sum is [1, 23, 4], but why length is 6? var nums1 = [1,2]; var nums2 = [3,4]; var set = nums1 + nums2; console.log(set.length); console.log(set);

26th Jul 2019, 8:23 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
2 Answers
+ 6
the sum of array is a string data type. [1,2]+[3,4]==="1,23,4" //true I hope this will help you to understand.
26th Jul 2019, 8:35 PM
Sarthak
Sarthak - avatar
+ 3
the length is 6 because it sees the commas as part of the string.
26th Jul 2019, 9:02 PM
Daniel M
Daniel M - avatar