+ 4

I don't understand length resulting from 2 set objects sum

Why by adding two objects with length 2 each one, the length of the result is 6, shouldn't it be 3? var nums1 = [1,2]; // length is 2 var nums2 = [3,4]; // length is 2 too var set = nums1 + nums2; //set is [1,23,4] console.log(set.length) // output is 6! why??   Enviar comentarios Historial Guardadas Comunidad

8th Aug 2019, 3:37 PM
Yoel
Yoel - avatar
2 Réponses
+ 8
when you add nums1 and nums2 then it becomes string "1,23,4" not array so the length of this string is 6 (including commas)
8th Aug 2019, 3:43 PM
VEDANG
VEDANG - avatar
+ 3
Now I see!! Thanks a lot VEDANG!!
8th Aug 2019, 4:03 PM
Yoel
Yoel - avatar