리액트 정리
[JS] Array() 생성자, Array.prototype.fill() 본문
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/Array
Array() 생성자
Array() 생성자는 새로운 Array 객체를 생성할 때 사용합니다.
developer.mozilla.org
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/fill
Array.prototype.fill()
fill() 메서드는 배열의 시작 인덱스부터 끝 인덱스의 이전까지 정적인 값 하나로 채웁니다.
developer.mozilla.org
틱택토 두번째 강좌에 나오고,, 자꾸 나와서 정리해봄
Array()로 Array 생성
.fill(filling value, start position, end position)로 채움.
[element0, element1, ..., elementN]
new Array(element0, element1[, ...[, elementN]])
new Array(arrayLength)
const array1 = [1, 2, 3, 4];
// fill with 0 from position 1 until position 3
console.log(Array(array1.length).fill(0, 1, 3));
// [undefined, 0, 0, undefined]
// fill with 5 from position 1
console.log(array1.fill(5, 1));
// expected output: [1, 5, 5, 5]
console.log(array1.fill(6));
// expected output: [6, 6, 6, 6]
console.log(Array(0))
// []
console.log(Array(2))
// [undefined, undefined]
'자바스크립트' 카테고리의 다른 글
[object Object]: What does this mean? (0) | 2021.01.05 |
---|---|
[JS] 삼항연산자 (0) | 2020.02.10 |
[JS] Array 메소드 2 (0) | 2020.01.30 |
[JS] Array 메소드 1 (0) | 2020.01.30 |