Movatterモバイル変換


[0]ホーム

URL:


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

TypedArray.of()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨September 2016⁩.

TheTypedArray.of() static method creates a newtyped array from a variable number of arguments. This method is nearly the same asArray.of().

Try it

const int16array = Int16Array.of("10", "20", "30", "40", "50");console.log(int16array);// Expected output: Int16Array [10, 20, 30, 40, 50]

Syntax

js
TypedArray.of()TypedArray.of(element1)TypedArray.of(element1, element2)TypedArray.of(element1, element2, /* …, */ elementN)

WhereTypedArray is one of:

Parameters

element1, …,elementN

Elements used to create the typed array.

Return value

A newTypedArray instance.

Description

SeeArray.of() for more details. There are some subtle distinctions betweenArray.of() andTypedArray.of():

  • If thethis value passed toTypedArray.of() is not a constructor,TypedArray.of() will throw aTypeError, whileArray.of() defaults to creating a newArray.
  • TypedArray.of() uses[[Set]] whileArray.of() uses[[DefineOwnProperty]]. Hence, when working withProxy objects, it callshandler.set() to create new elements rather thanhandler.defineProperty().

Examples

Using of()

js
Uint8Array.of(1); // Uint8Array [ 1 ]Int8Array.of("1", "2", "3"); // Int8Array [ 1, 2, 3 ]Float32Array.of(1, 2, 3); // Float32Array [ 1, 2, 3 ]Int16Array.of(undefined); // Int16Array [ 0 ]

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-%typedarray%.of

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp