How to concatenate array elements together

Description

The concat() method appends one array to another.

When no arguments are passed in, concat() clones the array and returns it. If one or more arrays are passed in, concat() concatenate the those arrays. If the values passed in are not arrays, they are simply appended to the end of the resulting array.

Example


var colors = ["A", "B", "C"]; 
var colors2 = colors.concat("D", ["E", "F"]); 
console.log(colors); //A,B,C
console.log(colors2); //A,B,C,D,E,F
//from w ww. ja  v  a2  s .  c  o m

The code above generates the following result.





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window