const array1 = [1, 2, 3, 4];
//2~3 자리까지 0으로 채운다 (4-1자리)
console.log(array1.fill(0, 2, 4));// [1, 2, 0, 0]
//1 자리부터 5로 채운다
console.log(array1.fill(5, 1));// [1, 5, 5, 5]
//전체를 6으로 채운다
console.log(array1.fill(6));// [6, 6, 6, 6]
'언어 정리 > JavaScript' 카테고리의 다른 글
Array.prototype.some() - .includes()와 비슷하지만 판별 함수 사용 (0) | 2022.11.29 |
---|---|
Array.prototype.splice(), Array.prototype.slice() 배열을 자르는 메서드 (0) | 2022.11.29 |
Array.prototype.reverse() 배열을 반대로 (0) | 2022.11.29 |
Set() 배열에서 중복을 제거해주는 메서드 (0) | 2022.11.28 |
JS 메서드 Array.prototype.pop(),push(),unshift(),shift() (0) | 2022.11.23 |