웹 프로그래밍 기초/객체

concat()메서드

별초롱언니 2025. 4. 7. 21:36

2개 이상의 배열을 하나의 배열로 묶기 위해 사용되는 메서드로, 기존 배열을 변경하는 것이 아니라 항상 새로운 배열을 생성한다. 

 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    let oldArray = ["apple","pear","orange"];
    let array1 = [1,2,3];
    let array2 = [4,5,6];
    let new_array = oldArray.concat(array1,array2);
    document.write(new_array + "<br>");

    let arr1 = ["Cecilie","Lone"];
    let myChildren = arr1.concat(["Emil","Tobias","Linus"]);
      document.write(myChildren + "<br>");
  </script>
</body>
</html>

 

'웹 프로그래밍 기초 > 객체' 카테고리의 다른 글

indexOf()  (0) 2025.04.07
push(), pop()  (0) 2025.04.07
toString(), join()  (0) 2025.04.07
내장 객체 (Array)  (0) 2025.04.07
class문법 활용한 객체 정의  (0) 2025.04.07