STUDY/Vue.js & Express.js & JS
[JS] fill() 메소드
쑥말고인절미
2022. 9. 5. 13:58
Array.prototype.filll()
- fill() 메소드는 배열의 시작 인덱스부터 끝 인덱스의 이전까지 정적인 값 하나로 채운다.
- fill(입력값, 시작 인덱스, 끝 인덱드-1);
- 예제
const array = [1, 2, 3, 4];
console.log(array.fill(0, 2, 4)); //출력 : [1, 2, 0, 0]
console.log(array.fill(5, 1)); //출력 : [1, 5, 5, 5]
console.log(array.fill(6)) //출력 : [6, 6, 6, 6]
참고링크
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/fill
Array.prototype.fill() - JavaScript | MDN
fill() 메서드는 배열의 시작 인덱스부터 끝 인덱스의 이전까지 정적인 값 하나로 채웁니다.
developer.mozilla.org