Array

Represents JavaScript array.

Dynamic array

{
    "type": "array",
    "items": { ... }
}

Fixed array

{
    "type": "array",
    "items": [{ ... }, { ... }]
}

Prop can be defined as dynamic array

      {
           "type": "array",
           "items": {
              "type": "string"
           }
       }

In this case above would be TS type string[].

... or as fixed

      {
           "type": "array",
           "items": [
                   {"type": "string" },  {"type": "number" }, {"type": "string" }
           ]
       }

In this case above would be TS type [string, number, string].

Options

uniqueItems

The value of this keyword MUST be a boolean. If this keyword has boolean value false, the instance validates successfully. If it has boolean value true, the instance validates successfully if all of its elements are unique. Omitting this keyword has the same behavior as a value of false.

minItems

The value of this keyword MUST be a non-negative integer. An array instance is valid against "minItems" if its size is greater than, or equal to, the value of this keyword. Omitting this keyword has the same behavior as a value of 0.

maxItems

The value of this keyword MUST be a non-negative integer. An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword.

Displaying in layout

How to loop

Crucial layout part in order to be able to loop over array items is LayoutPropArray. You specify `key` to the array prop. Anything inside `items` will automatically be repeated for each element in array prop.

{
        "type": "array",
        "key": "planets",
        "items": [  { "key": "planets[]" }   ]
}

Last updated

Was this helpful?