arr.fill(value[, start[, end]])
start
부터 end
가지를 value
로 채우기.인자
value
: 배열을 채울 값.
start
Optional: 시작 인덱스, 기본 값은 0.
end
Optional: 끝 인덱스, 기본 값은
this.length
.const array1 = [1, 2, 3, 4]; // 2부터 8까지 0으로 채우기 (기존 배열 길이를 넘어가진 않음) console.log(array1.fill(0, 2, 8)); // expected output: [1, 2, 0, 0] // 1부터 배열끝까지 5로 채우기 console.log(array1.fill(5, 1)); // expected output: [1, 5, 5, 5] // 전체 배열을 6으로 채우기 console.log(array1.fill(6)); // expected output: [6, 6, 6, 6]