Array.prototype.fill()
995 단어 JavaScriptfill메소드JavaScript
📌fill() 메서드란?
- 배열의 시작 인덱스부터 끝 인덱스의 이전까지 정적인 값 하나로 채운다.
- 구문 : arr.fill(value[, start[, end]])
- value : 배열을 채울 값 (필수)
- start : 시작 인덱스, 기본값은 0 (선택)
- end : 끝 인덱스, 기본값은 this.length (선택)
💻예시1.
const array1 = [1, 2, 3, 4];
// fill with 0 from position 2 until position 4
console.log(array1.fill(0, 2, 4));
// expected output: [1, 2, 0, 0]
// 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]
💻예시2.
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.fill("Kiwi"); // Kiwi,Kiwi,Kiwi,Kiwi
출처 : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/fill
Author And Source
이 문제에 관하여(Array.prototype.fill()), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@leesoyuun/Array.prototype.fill저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)