Array.concat

concat — Based on the given input array, returns a new array with the parameters provided added to the end.

If the parameter is an array, each value will be added.

Description

Array.concat(mixed item, [mixed item, …])

Parameters

Name Description Type Default Optional
item mixed No
item, … mixed Yes

Return values

The new array with the values added.

Examples

Example #1 – concat example
var array = [2, 4, 8, 16]; console.log(array); // [2, 4, 8, 16] console.log(array.concat(32, 64)); // [2, 4, 8, 16, 32, 64] console.log(array); // [2, 4, 8, 16]
Example #2 – concat example
var array = [2, 4, 8]; var array2 = [16, 32]; var array3 = [64, 128]; console.log(array); // [2, 4, 8] console.log(array.concat(array2, array3)); // [2, 4, 8, 16, 32, 64, 128] console.log(array); // [2, 4, 8]

External references