Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. TypedArray
  6. with()

TypedArray.prototype.with()

Baseline 2023
Newly available

Since ⁨July 2023⁩, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Thewith() method ofTypedArray instances is thecopying version of using thebracket notation to change the value of a given index. It returns a new typed array with the element at the given index replaced with the given value. This method has the same algorithm asArray.prototype.with().

Syntax

js
arrayInstance.with(index, value)

Parameters

index

Zero-based index at which to change the typed array,converted to an integer.

value

Any value to be assigned to the given index.

Return value

A new typed array with the element atindex replaced withvalue.

Exceptions

RangeError

Thrown ifindex >= array.length orindex < -array.length.

Description

SeeArray.prototype.with() for more details. This method is not generic and can only be called on typed array instances.

Examples

Using 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]

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-%typedarray%.prototype.with

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp