[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/concat [Back]  [Original]

Array.prototype.concat() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Array.prototype.concat()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

Array concat() . , .

In this article

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"]

js
concat()
concat(value0)
concat(value0, value1)
concat(value0, value1, /* , */ valueN)

valueN Optional

/ . valueN , concat . .

Array .

concat . . , . , , Symbol.isConcatSpreadable , . concat .

concat() . , .

concat() .

concat() . this ( ). , , @@isConcatSpreadable .

.

js
const letters = ["a", "b", "c"];
const numbers = [1, 2, 3];

const alphaNumeric = letters.concat(numbers);
console.log(alphaNumeric);
//  ['a', 'b', 'c', 1, 2, 3]

.

js
const num1 = [1, 2, 3];
const num2 = [4, 5, 6];
const num3 = [7, 8, 9];

const numbers = num1.concat(num2, num3);

console.log(numbers);
//  [1, 2, 3, 4, 5, 6, 7, 8, 9]

.

js
const letters = ["a", "b", "c"];

const alphaNumeric = letters.concat(1, [2, 3]);

console.log(alphaNumeric);
//  ['a', 'b', 'c', 1, 2, 3]

.

js
const num1 = [[1]];
const num2 = [2, [3]];

const numbers = num1.concat(num2);

console.log(numbers);
//  [[1], 2, [3]]

// num1    .
num1[0].push(4);

console.log(numbers);
//  [[1, 4], 2, [3]]

Symbol.isConcatSpreadable

concat , Symbol.isConcatSpreadable (: true) .

js
const obj1 = { 0: 1, 1: 2, 2: 3, length: 3 };
const obj2 = { 0: 1, 1: 2, 2: 3, length: 3, [Symbol.isConcatSpreadable]: true };
console.log([0].concat(obj1, obj2));
// [ 0, { '0': 1, '1': 2, '2': 3, length: 3 }, 1, 2, 3 ]

concat()

, .

js
console.log([1, , 3].concat([4, 5])); // [1, empty, 3, 4, 5]
console.log([1, 2].concat([3, , 5])); // [1, 2, 3, empty, 5]

concat()

this , this concat() . .

js
console.log(Array.prototype.concat.call({}, 1, 2, 3)); // [{}, 1, 2, 3]
console.log(Array.prototype.concat.call(1, 2, 3)); // [ [Number: 1], 2, 3 ]
const arrayLike = {
  [Symbol.isConcatSpreadable]: true,
  length: 2,
  0: 1,
  1: 2,
  2: 99, // length 2 concat() 
};
console.log(Array.prototype.concat.call(arrayLike, 3, 4)); // [1, 2, 3, 4]

Specification
ECMAScript 2027 LanguageSpecification
# sec-array.prototype.concat


Web Proxy Viewer  |  New URL  |  Original Page