TypedArray
.of()
method creates a new
typed array
from a variable number of arguments. This method is nearly the same as
Array.of()
.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
TypedArray.of(element0[, element1[, ...[, elementN]]])
where TypedArray is one of:
Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array
BigInt64Array
BigUint64Array
element
N
Elements of which to create the typed array.
A new
TypedArray
实例。
Some subtle distinctions between
Array.of()
and
TypedArray
.of()
:
this
value passed to
TypedArray
.of
is not a constructor,
TypedArray
.of
will throw a
TypeError
, where
Array.of
defaults to creating a new
Array
.
TypedArray
.of
使用
[[Put]]
where
Array.of
使用
[[DefineProperty]]
. Hence, when working with
Proxy
objects, it calls
handler.set
to create new elements rather than
handler.defineProperty
.
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 ]
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of '%TypedArray%.of' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
of
|
Chrome 45 | Edge 14 | Firefox 38 | IE No | Opera No | Safari 9.1 | WebView Android No | Chrome Android No | Firefox Android 38 | Opera Android No | Safari iOS 9.3 | Samsung Internet Android No | nodejs 4.0.0 |
完整支持
不支持
TypedArray
TypedArray.from()
TypedArray.of()
TypedArray.prototype.copyWithin()
TypedArray.prototype.entries()
TypedArray.prototype.every()
TypedArray.prototype.fill()
TypedArray.prototype.filter()
TypedArray.prototype.find()
TypedArray.prototype.findIndex()
TypedArray.prototype.forEach()
TypedArray.prototype.includes()
TypedArray.prototype.indexOf()
TypedArray.prototype.join()
TypedArray.prototype.keys()
TypedArray.prototype.lastIndexOf()
TypedArray.prototype.map()
TypedArray.prototype.reduce()
TypedArray.prototype.reduceRight()
TypedArray.prototype.reverse()
TypedArray.prototype.set()
TypedArray.prototype.slice()
TypedArray.prototype.some()
TypedArray.prototype.sort()
TypedArray.prototype.subarray()
TypedArray.prototype.toLocaleString()
TypedArray.prototype.toString()
TypedArray.prototype.values()
TypedArray.prototype[@@iterator]()
Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array
BigInt64Array
BigUint64Array
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()