배열 붙이기 concat() 메서드

개발 및 관리/Javascript 2023. 10. 31. 22:38 posted by HighLighter
반응형

//11. 배열 붙이기 concat() 메서드
console.clear();
const myArr1 = [1, 2, 3, 4];
const myArr2 = [5, 6, 7, 8];

const myArr3 = myArr1.concat(myArr2);

console.log(myArr1);
console.log(myArr2);
console.log('---------------------------------------------------- concat() 배열');
console.log(myArr3); // 1, 2, 3, 4, 5, 6, 7, 8

//문자열
const str1 = "Hello";
const str2 = "World";
console.log('---------------------------------------------------- concat() 문자열');
console.log(str1.concat(', ', str2)); // Hello, World

반응형