JavaScript Combine Two Arrays | ATLASSC.NET
Skip to main content
/// .DATA.FRAGMENT_20211108

JavaScript Combine Two Arrays

1 minAuthor: Z.SHINCHVEN

Array.prototype.push()

The push() method adds one or more elements to the end of an array and returns the new length of the array.

Syntax

push(element0)
push(element0, element1)
push(element0, element1, ... , elementN)

Example

const array1 = [1, 2, 3, 4];
const array2 = [5, 6, 7, 8];
array1.push(...array2);
// expected output: Array [1, 2, 3, 4, 6, 7, 8]

Array.prototype.concat()

The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.

Syntax

concat()
concat(value0)
concat(value0, value1)
concat(value0, value1, ... , valueN)

Example

const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);

console.log(array3);
// expected output: Array ["a", "b", "c", "d", "e", "f"]
RackNerd Billboard Banner
Share node:
/// .RELATED.DATA_STREAMSShared tags

Related posts

Scanning_database_for_correlations…

/// .UPLINK.SUBSCRIBE

Keep your deck synced with every new transmission from ATLASSC.NET. Subscribe over RSS or Atom, or wire the whole archive straight into your AI assistant with the MCP server.