This page was translated from English by the community.Learn more and join the MDN Web Docs community.
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() 메서드와 같은 알고리즘을 가지고 있습니다.
In this article
구문
js
arrayInstance.with(index, value)매개변수
반환 값
index의 요소 값이value로 대체된 새로운 형식화 배열.
예외
RangeErrorindex >= 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> |