카테고리 없음

자바스크립트 - concat() ?

CODE_PLAN 2022. 9. 1. 13:24

Array.prototype.concat()

concat() 메서드는 인자로 주어진 배열이나 값들을 기존 배열에 합쳐서 새 배열을 반환합니다.

  • 기존배열을 변경하지 않습니다.
  • 추가된 새로운 배열을 반환합니다.

ex)

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

 

output>

 Array ["a", "b", "c", "d", "e", "f"]