Basic Usage
Create an array schema that validates each element.Signature
ZodType
required
The schema to validate each array element against.
string | ZodArrayParams
Optional error message (string) or configuration object.
Properties
ZodType
Access the element schema.
Methods
min()
Set a minimum length for the array.number
required
Minimum number of elements required.
string | object
Optional error message or configuration object.
max()
Set a maximum length for the array.number
required
Maximum number of elements allowed.
string | object
Optional error message or configuration object.
length()
Set an exact length for the array.number
required
Exact number of elements required.
string | object
Optional error message or configuration object.
nonempty()
Require at least one element (equivalent to.min(1)).
The inferred type becomes a tuple type
[T, ...T[]] to ensure at least one element at the type level.string | object
Optional error message or configuration object.
unwrap()
Access the element schema.Combining Validations
You can chain multiple validation methods:Complex Element Types
Arrays can contain any Zod schema:Objects
Nested Arrays
Unions
Convenience Method
You can also create arrays using the.array() method on any schema:
Type Inference
Refinements
Add custom validation logic:Related
- z.tuple() - For fixed-length arrays with specific types
- z.set() - For sets with unique values
- z.record() - For key-value collections