---
title: "array(): function in Runtime, TypeShade API reference"
description: "array, a function in Runtime. A storage array of the structs of cls that data holds, a Buffer; or, with a typed array…"
url: https://typeshade.dev/api/array/
language: en
---

# `array()`

Function in Runtime

A storage array of the structs of cls that data holds, a Buffer; or, with a typed array, a Buffer of its scalars that keeps it on the device across calls (Amendment A1: `array(xs)` replaces resident(xs); Amendment A10, Q-I): a Buffer<`f32`> for a Float32Array or a number\[\], and so on; or, with a length and an element, a zeroed Buffer of scalars.

`import { array } from 'typeshade/runtime'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
function array<T extends object>(
  cls: ResourceClass<T, 'set'>,
  data: readonly Some<T>[],
): Buffer<T>;
function array<T extends ScalarArray>(value: T): Buffer<ElementOfTyped<T>>;
function array(value: readonly number[]): Buffer<number>;
function array<E extends ZeroedElement>(
  length: number,
  element: E,
): Buffer<ZeroedBufferElement<E>>;
```

## Parameters

**`cls` `ResourceClass<T, 'set'>`**

**`data` `readonly Some<T>[]`**

## Return value

`Buffer<T>`

a `Buffer<T>`.

## Exceptions

**`TypeError`**

`TypeError` as [`zeros`](https://typeshade.dev/api/zeros/) does, for `data` that is no array, for a value that is not an array (Amendment A11, Q3: write `uniform(Class, init)`, or pass the value to the call), and for an array that holds anything but numbers (A11, Q4: write `array(Class, data)` for structs).

## Description

What it makes belongs to the device in use (`using _ = device.use()`), or to the default owner when none is in use (R3): a `Buffer` of scalars is the one `device.array()` makes.

## In the guide

- [Language guide](https://typeshade.dev/guide/internals/)
- [Values and mutation](https://typeshade.dev/guide/internals/values-and-mutation/)
- [Layouts and resources](https://typeshade.dev/guide/internals/layouts-and-resources/)
- [Emitting and reflection](https://typeshade.dev/guide/internals/emitting-and-reflection/)
- [The CPU oracle](https://typeshade.dev/guide/internals/the-cpu-oracle/)

## See also

- [`zeros`](https://typeshade.dev/api/zeros/)
- [`semanticDiff`](https://typeshade.dev/api/semanticdiff/)
- [`constDecl`](https://typeshade.dev/api/constdecl/)
- [`resource`](https://typeshade.dev/api/resource/)
- [`storageBuffer`](https://typeshade.dev/api/storagebuffer/)

## Source

[`src/runtime/resource.ts`, line 1056](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/resource.ts#L1056), at commit af54ddad5
