Array Properties & Methods part 2

Combining Arrays



JavaScript's concat() method allows you to join arrays and create an entirely new array.

Example:
var c1 = ["HTML", "CSS"];
var c2 = ["JS", "C++"];
var courses = c1.concat(c2);
Try It Yourself

The courses array that results contains 4 elements (HTML, CSS, JS, C++).
The concat operation does not affect the c1 and c2 arrays - it returns the resulting concatenation as a new array.

Comments

Popular posts from this blog

String Operators

Introducing object part 3

The math object part 2