---
title: "array: shader function examples, uses and input limits"
description: "An array groups a fixed number of values of one element type. Use it for storing a short kernel, lookup table, or set of samples."
url: https://typeshade.dev/reference/functions/array/
language: en
---

# `array`

Function

An array groups a fixed number of values of one element type.

## Compare examples

The listed elements fill the array in input order. With no arguments, the constructor fills each element with zero.

**Example 1`array(1., 2., 3.)`**

**Result**

`[1, 2, 3]`

**Example 2`array<f32, 3>()`**

**Result**

`[0, 0, 0]`

**Example 3`array(vec2(1., 0.), vec2(0., 1.))`**

**Result**

`[[1, 0], [0, 1]]`

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

## When to use it

Use it for storing a short kernel, lookup table, or set of samples.

## Inputs and limits

The constructor count must match the fixed length. A zero constructor fills with the element type's zero, not an identity matrix or an arbitrary default.

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`fill`](https://typeshade.dev/reference/functions/fill/)
- [`zip`](https://typeshade.dev/reference/functions/zip/)

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Builds an `array<T, N>` from exactly N values of type T.

## Syntax

```ts
declare function array<V extends readonly unknown[]>(...values: V): array<[(V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never)] extends [never] ? V[number] : (V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never), V['length']>
declare function array<T, N extends number>(...values: readonly T[]): array<T, N>
```

A `number` in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.

`type f32 = number & { readonly [f32Tag]?: true }`

A `number` you write as a type is inferred from its uses, and `f32`, `i32` and `u32` fix a width; [the TypeScript constructs page](https://typeshade.dev/guide/language/from-typescript/) carries that row with the compiler's emit.

## Parameters

- `...values` `V``readonly T[]`

## Return value

`array<[(V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never)] extends [never] ? V[number] : (V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never), V['length']>``array<T, N>`

## Description

Without type arguments, `array(v1, v2, ..., vN)` reads T and N off the values, as WGSL does; `array<T, N>(v1, ..., vN)` names them, and `array<T, N>()` is the zero value, every element the zero of its type. An array has the methods `map`, `forEach`, `some`, `every` and `reduce`, each a counted loop over its elements that calls the function it is handed with the element, its `i32` index and the array.

## Examples

- [`path/palette/palette.shade.ts`](https://typeshade.dev/guide/examples/palette/)
- [`path/double-array/double-array.shade.ts`](https://typeshade.dev/guide/examples/double-array/)
- [`path/image-blur/image-blur.shade.ts`](https://typeshade.dev/guide/examples/image-blur/)
- [`path/sum-array/sum-array.shade.ts`](https://typeshade.dev/guide/examples/sum-array/)
- [`path/parallel-sum/parallel-sum.shade.ts`](https://typeshade.dev/guide/examples/parallel-sum/)
- [`path/histogram/histogram.shade.ts`](https://typeshade.dev/guide/examples/histogram/)
- [`gallery/capsule-corp-namek-class/capsule-corp-namek-class.shade.ts`](https://typeshade.dev/guide/examples/capsule-corp-namek-class/)
- [`gallery/path-tracer/path-tracer.shade.ts`](https://typeshade.dev/guide/examples/path-tracer/)
- [`gallery/array-length/array-length.shade.ts`](https://typeshade.dev/guide/examples/array-length/)
- [`gallery/array-literal-ramp/array-literal-ramp.shade.ts`](https://typeshade.dev/guide/examples/array-literal-ramp/)
- [`gallery/array-methods/array-methods.shade.ts`](https://typeshade.dev/guide/examples/array-methods/)
- [`gallery/atomic-histogram/atomic-histogram.shade.ts`](https://typeshade.dev/guide/examples/atomic-histogram/)
- [`gallery/bare-position/bare-position.shade.ts`](https://typeshade.dev/guide/examples/bare-position/)
- [`gallery/bit-bump/bit-bump.shade.ts`](https://typeshade.dev/guide/examples/bit-bump/)
- [`gallery/bool-select/bool-select.shade.ts`](https://typeshade.dev/guide/examples/bool-select/)
- [`gallery/clip-planes/clip-planes.shade.ts`](https://typeshade.dev/guide/examples/clip-planes/)
- [`gallery/closures/closures.shade.ts`](https://typeshade.dev/guide/examples/closures/)
- [`gallery/compute-reduction-twin/compute-reduction-twin.shade.ts`](https://typeshade.dev/guide/examples/compute-reduction-twin/)
- [`gallery/compute-sync/compute-sync.shade.ts`](https://typeshade.dev/guide/examples/compute-sync/)
- [`gallery/cube-array-gather/cube-array-gather.shade.ts`](https://typeshade.dev/guide/examples/cube-array-gather/)
- [`gallery/cube-env/cube-env.shade.ts`](https://typeshade.dev/guide/examples/cube-env/)
- [`gallery/default-args/default-args.shade.ts`](https://typeshade.dev/guide/examples/default-args/)
- [`gallery/generic-class/generic-class.shade.ts`](https://typeshade.dev/guide/examples/generic-class/)
- [`gallery/generic-helpers/generic-helpers.shade.ts`](https://typeshade.dev/guide/examples/generic-helpers/)
- [`gallery/gpu-console/gpu-console.shade.ts`](https://typeshade.dev/guide/examples/gpu-console/)
- [`gallery/higher-order/higher-order.shade.ts`](https://typeshade.dev/guide/examples/higher-order/)
- [`gallery/id-pick/id-pick.shade.ts`](https://typeshade.dev/guide/examples/id-pick/)
- [`gallery/integer-math/integer-math.shade.ts`](https://typeshade.dev/guide/examples/integer-math/)
- [`gallery/kernel-array-methods/kernel-array-methods.shade.ts`](https://typeshade.dev/guide/examples/kernel-array-methods/)
- [`gallery/kernel-push/kernel-push.shade.ts`](https://typeshade.dev/guide/examples/kernel-push/)
- [`gallery/kernel-set-unique/kernel-set-unique.shade.ts`](https://typeshade.dev/guide/examples/kernel-set-unique/)
- [`gallery/loop-kernel/loop-kernel.shade.ts`](https://typeshade.dev/guide/examples/loop-kernel/)
- [`gallery/loop-on-cpu/loop-on-cpu.shade.ts`](https://typeshade.dev/guide/examples/loop-on-cpu/)
- [`gallery/loop-reduction/loop-reduction.shade.ts`](https://typeshade.dev/guide/examples/loop-reduction/)
- [`gallery/loop-struct-array/loop-struct-array.shade.ts`](https://typeshade.dev/guide/examples/loop-struct-array/)
- [`gallery/loops-over-data/loops-over-data.shade.ts`](https://typeshade.dev/guide/examples/loops-over-data/)
- [`gallery/mixin-surface/mixin-surface.shade.ts`](https://typeshade.dev/guide/examples/mixin-surface/)
- [`gallery/msaa-resolve/msaa-resolve.shade.ts`](https://typeshade.dev/guide/examples/msaa-resolve/)
- [`gallery/null-values/null-values.shade.ts`](https://typeshade.dev/guide/examples/null-values/)
- [`gallery/optional-fields/optional-fields.shade.ts`](https://typeshade.dev/guide/examples/optional-fields/)
- [`gallery/optional-values/optional-values.shade.ts`](https://typeshade.dev/guide/examples/optional-values/)
- [`gallery/orbit-inout/orbit-inout.shade.ts`](https://typeshade.dev/guide/examples/orbit-inout/)
- [`gallery/packed-bytes/packed-bytes.shade.ts`](https://typeshade.dev/guide/examples/packed-bytes/)
- [`gallery/packing-bitcast/packing-bitcast.shade.ts`](https://typeshade.dev/guide/examples/packing-bitcast/)
- [`gallery/palette-const/palette-const.shade.ts`](https://typeshade.dev/guide/examples/palette-const/)
- [`gallery/particle-step/particle-step.shade.ts`](https://typeshade.dev/guide/examples/particle-step/)
- [`gallery/pick-composite/pick-composite.shade.ts`](https://typeshade.dev/guide/examples/pick-composite/)
- [`gallery/ray-class/ray-class.shade.ts`](https://typeshade.dev/guide/examples/ray-class/)
- [`gallery/reference-parameters/reference-parameters.shade.ts`](https://typeshade.dev/guide/examples/reference-parameters/)
- [`gallery/shadow-compare/shadow-compare.shade.ts`](https://typeshade.dev/guide/examples/shadow-compare/)
- [`gallery/shape-inheritance/shape-inheritance.shade.ts`](https://typeshade.dev/guide/examples/shape-inheritance/)
- [`gallery/subgroup-reduce/subgroup-reduce.shade.ts`](https://typeshade.dev/guide/examples/subgroup-reduce/)
- [`gallery/tuple-and-brand/tuple-and-brand.shade.ts`](https://typeshade.dev/guide/examples/tuple-and-brand/)
- [`gallery/uniform-array/uniform-array.shade.ts`](https://typeshade.dev/guide/examples/uniform-array/)
- [`gallery/workgroup-override/workgroup-override.shade.ts`](https://typeshade.dev/guide/examples/workgroup-override/)
- [`gallery/workgroup-reduce/workgroup-reduce.shade.ts`](https://typeshade.dev/guide/examples/workgroup-reduce/)
- [`gallery/workgroup-scratch/workgroup-scratch.shade.ts`](https://typeshade.dev/guide/examples/workgroup-scratch/)
- [`gallery/workgroup-tile-2d/workgroup-tile-2d.shade.ts`](https://typeshade.dev/guide/examples/workgroup-tile-2d/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
