<html>
  <head> </head>
  <body>
    <script>
      // 배열
      // 1. Array
      // 10개의 공간의 배열을 생성 (아직 초기화 안됨)
      const a = Array(10);

      // 2. fill
      // 배열의 모든 공간에 디폴트 값을 넣어주기
      a.fill(0); // (10) [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

      // 3. map
      // 배열의 원소들을 매핑해서 새로운 배열에 생성
      // Array.map(함수)
      const b = a.map((_elem, _idx) => {
        return _idx + 1;
      });

      console.log(a); // (10) [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
      console.log(b); // (10) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    </script>
  </body>
</html>
복사했습니다!