Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Zod · Type Alias

ZodArray

ZodArray is the schema type created for arrays with z.array(elementSchema) or elementSchema.array(). It validates each item and supports array length constraints such as nonempty, min, max, and length.

How it works

ZodArray is the array schema produced by wrapping an element schema with z.array() or an element schema’s .array() method. It validates each item against the inner schema and can apply array-level size constraints such as nonempty, min, max, and length.

Syntax

z.array(elementSchema)
elementSchema.array()

Parameters

NameTypeDescription
elementSchemaZodTypeThe Zod schema each array element must satisfy.

Returns

A ZodArray schema that validates arrays and their elements.

Key points

  • Create an array schema with z.array(elementSchema), where elementSchema determines the required type of every item.
  • The functional and method forms are equivalent ways to construct an array schema.
  • An array schema exposes its element schema, which is useful when composing or inspecting schemas.
  • Use nonempty when an empty array should be rejected.
  • Use min to require at least a specified number of elements.
  • Use max to cap the number of elements.
  • Use length when the array must contain exactly a specified number of elements.

Example: Validate a bounded string array

import { z } from "zod";

const tags = z.array(z.string()).min(1).max(3);

console.log(tags.parse(["typescript", "zod"]));

Creates an array schema whose elements are strings and whose length must be between one and three items.

When to use it

Validate collection inputs

Validate JSON or API payloads containing lists of primitive values or structured records.

Enforce collection size

Reject empty lists or enforce lower and upper bounds on submitted items.

Build nested schemas

Compose nested schemas for arrays of objects, unions, or other arrays.

Interview questions

QHow do you define an array schema in Zod?

Use z.array(elementSchema) to construct an array schema. The equivalent shorthand is elementSchema.array(), such as z.string().array() for an array of strings.

Follow-up: How would you restrict the number of elements? Chain an array-specific constraint such as .min(), .max(), .length(), or .nonempty() after creating the array schema.

QWhat does the argument to z.array() represent?

The schema passed to z.array() describes each array element. For example, z.array(z.string()) accepts only arrays whose items validate as strings.

Follow-up: How can you inspect the element schema? Use the array schema’s inner-schema access described by the API documentation.

QWhich length constraints are available for arrays?

Zod provides array-specific validations for requiring at least one item, setting minimum or maximum size, and requiring an exact length. These are expressed with .nonempty(), .min(), .max(), and .length().

Follow-up: What happens if a value violates either the item schema or an array-size constraint? Parsing fails validation rather than returning the invalid value.

  • z.array
  • ZodString
  • nonempty
  • min
  • max
  • length
  • ZodObject

Source: Defining schemas - Zod. Checked 2026-10-15.