Skip to content

API Int32Array

Liu.Yandong.Hanks edited this page Aug 21, 2026 · 3 revisions

Int32Array

Fixed-length packed array of signed 32-bit integers.

Script API Reference

Overview

Int32Array is a primitive-backed array for allocation-efficient numeric workloads such as indexes, distances, counters, and tight numeric loops. Elements live in contiguous native int storage, so the array avoids the per-element object allocation of a general Array.

The length is fixed at construction. push, pop, and element deletion are unavailable; elements are read and written through numeric indexes.

var scores = new Int32Array(3);
scores[0] = 42;
return scores[0]; // 42

Warning

Indexing outside 0 to length - 1 raises a runtime error. Validate computed indexes before reading or writing.

Use Array instead when the element type must vary or when the collection has to grow.

Constructors

new Int32Array([length])

Parameters

Name Type Required Description
length number No Non-negative element count. Omitting it creates an empty array.

Returns

Int32Array — a fixed-length array whose elements start at 0.

Example

var counters = new Int32Array(4);
return counters[3]; // 0

Properties

values.length

Returns

number — the fixed element count.

Behavior

Read-only. The value never changes for a given instance.

Example

return new Int32Array(4).length; // 4

Methods

values.fill([value])

Parameters

Name Type Required Description
value number No Value written to every element. Defaults to 0.

Returns

Int32Array — this array, so calls can be chained.

Behavior

The value is converted to a signed 32-bit integer before it is stored, and every element is overwritten in place.

Example

var slots = new Int32Array(3);
slots.fill(7);
return slots[2]; // 7

Clone this wiki locally