[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#syntax [Back]  [Original]

TypedArray - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

TypedArray

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

TypedArray ( ) (ArrayBuffer). TypedArray, TypedArray. , . . , .

In this article

new TypedArray(); //   ES2017
new TypedArray(length);
new TypedArray(typedArray);
new TypedArray(object);
new TypedArray(buffer [, byteOffset [, length]]);

 TypedArray()     :

Int8Array(), Uint8Array(), Uint8ClampedArray(), Int16Array(), Uint16Array(), Int32Array(), Uint32Array(), Float32Array(), Float64Array()

length

length BYTES_PER_ELEMENT ,

typedArray

typedArray, (, Int32Array), typedArray . typedArray . typedArray typedArray

object

, TypedArray.from()

buffer, byteOffset, length

buffer byteOffset length, , buffer ArrayBuffer. byteOffset length () , . (byteOffset length) , buffer; length, , byteOffset.

ECMAScript 2015 TypedArray, TypedArray-. : - %TypedArray% TypedArray . Object.getPrototypeOf(...) (, Int8Array.prototype). TypedArrays %TypedArray%. , (TypedArray.prototype) %TypedArray%.prototype.

%TypedArray% . new TypeError, , JS-, . , %TypedArray% () TypedArray.

TypedArray (, Int8Array), , ArrayBuffer , . , %TypedArray%.prototype, , , .

(, arr[12]). , , . ArrayBuffer . .

js
//      
var int16 = new Int16Array(2);
int16[0] = 42;
console.log(int16[0]); // 42

//     ( 20     "foo")
Int8Array.prototype[20] = "foo";
new Int8Array(32)[20]; // 0
//         
Int8Array.prototype[20] = "foo";
new Int8Array(8)[20]; // undefined
//     
Int8Array.prototype[-1] = "foo";
new Int8Array(8)[-1]; // undefined

//   
Int8Array.prototype.foo = "bar";
new Int8Array(32).foo; // "bar"

TypedArray

() Web IDL C
Int8Array -128 127 1 8- byte int8_t
Uint8Array 0 255 1 8- octet uint8_t
Uint8ClampedArray 0 255 1 8- ( 0 255) octet uint8_t
Int16Array -32768 32767 2 16- short int16_t
Uint16Array 0 65535 2 16- unsigned short uint16_t
Int32Array -2147483648 2147483647 4 32- long int32_t
Uint32Array 0 4294967295 4 32- unsigned long uint32_t
Float32Array 1.2x10-38 to 3.4x1038 4 32- IEEE- (7 , 1.123456) unrestricted float float
Float64Array 5.0x10-324 to 1.8x10308 8 64- IEEE- (16 , , 1.123...15) unrestricted double double

TypedArray.BYTES_PER_ELEMENT

.

TypedArray.length

"", 0.

TypedArray.name

. , "Int8Array".

get TypedArray[@@species]

. .

TypedArray

TypedArray-.

TypedArray.from()

. Array.from().

TypedArray.of()

, . Array.of().

TypedArray

TypedArrays- TypedArray.

()

, TypedArray, , , Arrays. Javascript- , Typed Array.

js
var typedArrayTypes = [
  Int8Array,
  Uint8Array,
  Uint8ClampedArray,
  Int16Array,
  Uint16Array,
  Int32Array,
  Uint32Array,
  Float32Array,
  Float64Array,
];

for (var k in typedArrayTypes)
  for (var v in Array.prototype)
    if (
      Array.prototype.hasOwnProperty(v) &&
      !typedArrayTypes[k].prototype.hasOwnProperty(v)
    )
      typedArrayTypes[k].prototype[v] = Array.prototype[v];

Specification
ECMAScript 2027 LanguageSpecification
# sec-typedarray-objects


Web Proxy Viewer  |  New URL  |  Original Page