https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/concat
Array.prototype.concat() - JavaScript | MDN
concat() 메서드는 인자로 주어진 배열이나 값들을 기존 배열에 합쳐서 새 배열을 반환합니다.
developer.mozilla.org
https://www.w3schools.com/jsref/jsref_concat_array.asp
JavaScript Array concat() Method
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
www.w3schools.com
concat()은 일반적으로 사용되는 것 처럼 두개의 배열을 추가하는 하여 새 배열을 반환한다.
주의해야할 점은 concat()으로 병합시 배열내의 아이템의 type과 관련없이 단순히 추가하기만 한다는 것이다.
const array1 = ['1', '2', '3'];
const array2 = [1, 2, 3];
const array3 = [{ name : "1" }];
const array4 = array1.concat(array2).concat(array3);
console.log(array4);
//Array ["1", "2", "3", 1, 2, 3, Object { name: "1" }]
숫자, 문자, Object와 같은 type과 상관없이 단순히 추가하기만 한다.
'Javascript' 카테고리의 다른 글
Array.prototype.copyWithin() (0) | 2021.11.15 |
---|---|
Array.prototype.find() (0) | 2021.11.12 |
JavaScript에서 true로 인식되는 값; 참 같은 값; Truthy (0) | 2021.11.11 |
JavaScript에서 false로 인식되는 값; 거짓같은 값; Falsy (0) | 2021.11.11 |
Array.prototype.sort() (0) | 2021.11.10 |