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

TypedArray - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

TypedArray

Baseline

20157

TypedArray TypedArray TypedArray

TypedArray %TypedArray% JavaScript TypedArray %TypedArray% TypedArray Object.getPrototypeOf(Int8Array)

TypedArray Int8Array ArrayBuffer ArrayBuffer %TypedArray%.prototype

TypedArray

() Web IDL
Int8Array -128 127 1 byte
Uint8Array 0 255 1 octet
Uint8ClampedArray 0 255 1 octet
Int16Array -32768 32767 2 short
Uint16Array 0 65535 2 unsigned short
Int32Array -2147483648 2147483647 4 long
Uint32Array 0 4294967295 4 unsigned long
Float16Array -65504 65504 2
Float32Array -3.4E38 3.4E38 1.2E-38 4 unrestricted float
Float64Array -1.8E308 1.8E308 5E-324 8 unrestricted double
BigInt64Array -263 to 263 - 1 8 bigint
BigUint64Array 0 to 264 - 1 8 bigint

ArrayBuffer

  • (Uint8Array, Uint16Array, Uint32Array, BigUint64Array)
  • (Int8Array, Int16Array, Int32Array, BigInt64Array) 2
  • (Float16Array, Float32Array, Float64Array) IEEE 754 Number JavaScript Float64Array Float32Array 52 23 11 8 Float16Array 10 5 NaN
  • Uint8ClampedArray Uint8Array 0 255

Int8ArrayUint8ArrayUint8ClampedArray DataView

  • Uint8ClampedArray
  • Uint8ClampedArray 0 255 255 255 0 0 2 0.5 01.5 22.5 2
  • Float16Array Float32Array "round to even" 64 32 16 Math.fround() Math.f16round()

TypedArray TypedArray TypedArray

3undefined buffer

js
const buffer = new ArrayBuffer(8, { maxByteLength: 16 });
const float32 = new Float32Array(buffer);

console.log(float32.byteLength); // 8
console.log(float32.length); // 2

buffer.resize(12);

console.log(float32.byteLength); // 12
console.log(float32.length); // 3

3 length buffer

js
const buffer = new ArrayBuffer(8, { maxByteLength: 16 });
const float32 = new Float32Array(buffer, 0, 2);

console.log(float32.byteLength); // 8
console.log(float32.length); // 2
console.log(float32[0]); // 0

buffer.resize(12);

console.log(float32.byteLength); // 8
console.log(float32.length); // 2
console.log(float32[0]); // 0

buffer 0

js
const buffer = new ArrayBuffer(8, { maxByteLength: 16 });
const float32 = new Float32Array(buffer, 0, 2);

buffer.resize(7);

console.log(float32.byteLength); // 0
console.log(float32.length); // 0
console.log(float32[0]); // undefined

buffer

js
buffer.resize(8);

console.log(float32.byteLength); // 8
console.log(float32.length); // 2
console.log(float32[0]); // 0 - back in bounds again!

byteOffset

js
const buffer = new ArrayBuffer(8, { maxByteLength: 16 });
const float32 = new Float32Array(buffer, 4);
// float32 4 
//  4 
// 
buffer.resize(3);
console.log(float32.byteLength); // 0

new TypeError

js
new (Object.getPrototypeOf(Int8Array))();
// TypeError: Abstract class TypedArray not directly constructable

Int8Array BigInt64Array

js
new TypedArray()
new TypedArray(length)
new TypedArray(typedArray)
new TypedArray(object)

new TypedArray(buffer)
new TypedArray(buffer, byteOffset)
new TypedArray(buffer, byteOffset, length)

TypedArray

: TypedArray new new TypeError

typedArray

TypedArray typedArray TypedArray typedArray Int32Array TypedArray BigInt64Array BigUint64ArraytypedArray typedArray typedArray

object

TypedArray TypedArray.from()

length

length BYTES_PER_ELEMENT 0 0 length

buffer, byteOffset , length

ArrayBuffer SharedArrayBuffer byteOffset length byteOffset length BYTES_PER_ELEMENT buffer length buffer byteOffset length

TypeArray

TypeError

  • typedArray
  • typedArray buffer
RangeError

  • buffer length byteOffset
  • byteOffset 0 253 - 1
  • byteOffset + length * TypedArray.BYTES_PER_ELEMENT > buffer.byteLength

TypedArray TypedArray

TypedArray[Symbol.species]

TypedArray

TypedArray.BYTES_PER_ELEMENT

TypedArray

TypedArray TypedArray

TypedArray.from()

TypedArray Array.from()

TypedArray.of()

TypedArray Array.of()

TypedArray.prototype TypedArray

TypedArray.prototype.buffer

ArrayBuffer

TypedArray.prototype.byteLength

()

TypedArray.prototype.byteOffset

ArrayBuffer ()

TypedArray.prototype.constructor

TypedArray.prototype.constructor TypedArray constructor

TypedArray.prototype.length

TypedArray.prototype[Symbol.toStringTag]

TypedArray.prototype[Symbol.toStringTag] this undefined Object.prototype.toString() TypedArray toString() Object.prototype.toString.call() thisArg

TypedArray

TypedArray.prototype.BYTES_PER_ELEMENT

TypedArray

TypedArray TypedArray

TypedArray.prototype.at()

TypedArray.prototype.copyWithin()

Array.prototype.copyWithin()

TypedArray.prototype.entries()

Array.prototype.entries()

TypedArray.prototype.every()

1 false true Array.prototype.every()

TypedArray.prototype.fill()

Array.prototype.fill()

TypedArray.prototype.filter()

true Array.prototype.filter()

TypedArray.prototype.find()

undefined Array.prototype.find()

TypedArray.prototype.findIndex()

-1 Array.prototype.findIndex()

TypedArray.prototype.findLast()

undefined Array.prototype.findLast()

TypedArray.prototype.findLastIndex()

-1 Array.prototype.findLastIndex()

TypedArray.prototype.forEach()

Array.prototype.forEach()

TypedArray.prototype.includes()

true false Array.prototype.includes()

TypedArray.prototype.indexOf()

-1 Array.prototype.indexOf()

TypedArray.prototype.join()

1 Array.prototype.join()

TypedArray.prototype.keys()

Array.prototype.keys()

TypedArray.prototype.lastIndexOf()

-1 Array.prototype.lastIndexOf()

TypedArray.prototype.map()

Array.prototype.map()

TypedArray.prototype.reduce()

Array.prototype.reduce()

TypedArray.prototype.reduceRight()

Array.prototype.reduce()

TypedArray.prototype.reverse()

Array.prototype.reverse()

TypedArray.prototype.set()

TypedArray.prototype.slice()

Array.prototype.slice()

TypedArray.prototype.some()

1 true false Array.prototype.some()

TypedArray.prototype.sort()

Array.prototype.sort()

TypedArray.prototype.subarray()

TypedArray

TypedArray.prototype.toLocaleString()

Array.prototype.toLocaleString()

TypedArray.prototype.toReversed()

TypedArray.prototype.toSorted()

TypedArray.prototype.toString()

Array.prototype.toString()

TypedArray.prototype.values()

Array.prototype.values()

TypedArray.prototype.with()

TypedArray.prototype[Symbol.iterator]()

() ArrayBuffer

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

//  (Fx 25)
Int8Array.prototype[20] = "foo";
new Int8Array(32)[20]; // 0
// even when out of bound
Int8Array.prototype[20] = "foo";
new Int8Array(8)[20]; // undefined
// or with negative integers
Int8Array.prototype[-1] = "foo";
new Int8Array(8)[-1]; // undefined

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

TypedArray ArrayBuffer TypedArray

js
const i8 = Int8Array.of(1, 2, 3);
Object.freeze(i8);
// TypeError: Cannot freeze array buffer views with elements

ByteOffset

ArrayBuffer TypedArray byteOffset BYTES_PER_ELEMENT

js
const i32 = new Int32Array(new ArrayBuffer(4), 1);
// RangeError: start offset of Int32Array should be a multiple of 4
js
const i32 = new Int32Array(new ArrayBuffer(4), 0);

ByteLength

byteOffset TypedArray ArrayBuffer byteLength BYTES_PER_ELEMENT

js
const i32 = new Int32Array(new ArrayBuffer(3));
// RangeError: byte length of Int32Array should be a multiple of 4
js
const i32 = new Int32Array(new ArrayBuffer(4));

ECMAScript 2027 LanguageSpecification
# sec-typedarray-objects


Web Proxy Viewer  |  New URL  |  Original Page