자바스크립트 배열 채우기()
예
모든 요소를 값으로 채웁니다.
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.fill("Kiwi");
마지막 두 요소를 채우십시오.
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.fill("Kiwi", 2, 4);
정의 및 사용
이 fill()
메서드는 배열의 지정된 요소를 값으로 채웁니다.
이 fill()
메서드는 원래 배열을 덮어씁니다.
시작 및 종료 위치를 지정할 수 있습니다. 그렇지 않은 경우 모든 요소가 채워집니다.
통사론
array.fill(value, start, end)
매개변수
Parameter | Description |
value | Required. The value to fill in. |
start | Optional. The start index (position). Default is 0. |
end | Optional. The stop index (position). Default is array length. |
반환 값
유형 | 설명 |
배열 | 채워진 배열입니다. |
브라우저 지원
fill()
ECMAScript6(ES6) 기능입니다.
ES6(JavaScript 2015)은 모든 최신 브라우저에서 지원됩니다.
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
fill()
Internet Explorer 11(또는 이전)에서는 지원되지 않습니다.