0

I was trying to concatenate two array using + sign but result i was getting is:first array's last element is concatenated to first element of second array why it is happening is there is any specific reason I tried

var a=[1,2,3]; 
var b=[5,7,8]; 
console.log(a+b);

I got result 1,2,35,7,8

Roli Agrawal
  • 2,356
  • 3
  • 23
  • 28

1 Answers1

5

+ operator turns arrays into strings, use Array.prototype.concat instead.

console.log(a.concat(b));
keune
  • 5,779
  • 4
  • 34
  • 50