2018/05/23
-
Javscript Array 복사(copy)컴퓨터/HTML & JS & TS 2018. 5. 23. 18:54
AirBnB ESLint(자바스크립트 표준)에 따르면 (https://github.com/airbnb/javascript#es6-array-spreads) const len = items.length; const itemsCopy = []; let i; for (i = 0; i < len; i += 1) { itemsCopy[i] = items[i]; } 위는 Bad 코드이며 아래처럼 '...' (spread) 오퍼레이터를 사용하라고 권장한다. const items = [1, 2, 3, 4, 5]; const itemsCopy = [...items];