728x90

✨ 원하는 개수만큼 array를 선언하는 방법
(e.g., const arr = new Array(100)) 왼쪽처럼 선언하면 간단하게 100개의 array를 생성할 수 있다.

💻Example Code

const arr = new Array(100);

console.log( arr );
console.log( arr.length);

실행 결과(100개의 비어있는 Array 값, Array의 길이는 100)

😋 가끔 큰 index의 Array를 다룰 때, undefined보다는 하나의 값을 전체적으로 지정해주고 싶을 때가 있다. 그때 사용하면 된다.
백준 4673 셀프 넘버(Self Number)에서 유용하게 사용했다.

👉 자세한 내용은 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

 

Array

The JavaScript Array class is a global object that is used in the construction of arrays; which are high-level, list-like objects.

developer.mozilla.org

 

'JavaScript > Built-in Method etc.' 카테고리의 다른 글

String.charCodeAt()  (0) 2019.12.31
new String()  (0) 2019.12.29
Array.prototype.메소드() 만들기  (0) 2019.12.29
Array.prototype.fill()  (0) 2019.12.29
String.prototype.replace()  (0) 2019.12.29

+ Recent posts