JavaScript Array Method : concat()

The concat() method is used to create a new array by merging or concatenating existing arrays and return value is the length of array. The syntax of concat() method is :
Example :
  var vagitables = ["Potato", "Onion", "Tomato"];
  var fruits = ["Apple", "Mango", "Banana"];
  document.write("vagitables : " + vagitables + "<br/>");
  document.write("fruits : " + fruits + "<br/>");
  var foods = vagitables.concat(fruits);
  document.write("The concatneted Array will be : " + foods);
Output :

Although JavaScript automatically converts an array to a comma separated string when a primitive value is expected.

Next Topic :