본문 바로가기
JavaScript/Core

[ecmaScript6] TypedArray.prototype.fill()

by Jundol 2015. 10. 28.

본 포스팅은 MDN 에 있는 번역되지 않은 문서를 번역 봉사에 참여한 후 블로그에 옮겨놓는 포스팅 입니다.

추가적인 사담이 존재합니다.



TypedArray.prototype.fill()

fill 메소드는 배열의 모든 요소를 지정한 시작 인덱스부터 종료 인덱스까지 정적인 값으로 채우는 메소드입니다.
TypedArray.prototype.fill 메소드는 Array.prototype.fill 메소드와 동일한 알고리즘을 가지고 있습니다.
TypedArray 는 typed array types 이곳에 있는 것 중 하나 입니다.

사담 : 개인적으로 정말 마음에 안듭니다. fill 이라는 범용적으로 사용되는 단어를 코어함수의 이름으로 사용한건 정말 별로네요...


문법

typedarray.fill(value[, start = 0[, end = this.length]])

매개변수

value
배열에 채워넣을 값.
start
선택사항. 시작 위치. 기본값은 0.
end
선택사항. 종료 위치 (종료위치를 포함하지않습니다. 즉, end -1 까지만 해당됩니다.). 기본값 this.length(배열의 길이).

설명

start 와 end 사이에 요소들을 채웁니다.

fill 메소드는 value, start 그리고 and 3개의 매개변수를 요구합니다. start 와 end 매개변수는 선택사항이며 기본값은 0 과 지정한 배열객체의 길이값 입니다.

만약 start 매개변수가 음수이면, start 의 값은 배열의 길이값을 합한 결과가 시작지점이 되고, 만약 end 가 음수라면, end 매개변수와 배열의 길이값을 합한 결과가 종료지점이 됩니다.

예시

new Uint8Array([1, 2, 3]).fill(4);         // Uint8Array [4, 4, 4]
new Uint8Array([1, 2, 3]).fill(4, 1);      // Uint8Array [1, 4, 4]
new Uint8Array([1, 2, 3]).fill(4, 1, 2);   // Uint8Array [1, 4, 3]
new Uint8Array([1, 2, 3]).fill(4, 1, 1);   // Uint8Array [1, 2, 3]
new Uint8Array([1, 2, 3]).fill(4, -3, -2); // Uint8Array [4, 2, 3]

특징

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'TypedArray.prototype.fill' in that specification.
StandardInitial definition.

브라우저 지원

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic supportNot supported37 (37)Not supportedNot supportedNot supported

See also

원본 : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill

댓글