개발/Javascript
배열(Arrays)
DANIEL.OH
2018. 3. 11. 13:55
배열(Arrays)
Use the literal syntax for array creation.
배열을 작성 할 때는 리터럴 구문을 사용해 주십시오.
// bad const items = new Array(); // good const items = [];
Use Array#push instead of direct assignment to add items to an array.
직접 배열에 항목을 대입하지 말고, Array#push를 이용해 주십시오.
const someStack = []; // bad someStack[someStack.length] = 'abracadabra'; // good someStack.push('abracadabra');
배열을 복사할때는 배열의 확장연산자
...를 이용해 주십시오.// bad const len = items.length; const itemsCopy = []; let i; for (i = 0; i < len; i++) { itemsCopy[i] = items[i]; } // good const itemsCopy = [...items];
To convert an array-like object to an array, use Array#from.
array-like 오브젝트를 배열로 변환하는 경우는 Array#from을 이용해 주십시오.
const foo = document.querySelectorAll('.foo'); const nodes = Array.from(foo);