TypedArray.prototype.with()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2023년 7월.
TypedArray 인스턴스의 with() 메서드는 대괄호 표기법을 사용하여 주어진 인덱스의 값을 변경하는 복사 버전입니다. 이 메서드는 주어진 인덱스의 요소가 주어진 값으로 대체된 새로운 형식화 배열을 반환합니다. 이 메서드는 Array.prototype.with() 메서드와 같은 알고리즘을 가지고 있습니다.
구문
js
arrayInstance.with(index, value)
매개변수
반환 값
index의 요소 값이 value로 대체된 새로운 형식화 배열.
예외
RangeError-
index >= array.length혹은index < -array.length일때 발생합니다.
설명
보다 상세한 설명은 Array.prototype.with()를 참고하시기 바랍니다. 이 메서드는 제네릭이 아니며 형식화 배열 인스턴스에서만 호출할 수 있습니다.
예제
>with() 사용하기
js
const arr = new Uint8Array([1, 2, 3, 4, 5]);
console.log(arr.with(2, 6)); // Uint8Array [1, 2, 6, 4, 5]
console.log(arr); // Uint8Array [1, 2, 3, 4, 5]
명세서
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-%typedarray%.prototype.with> |