array

array([schema])

Effect

Get a schema object of type array.

Arguments

  • [schema] (schema) - The schema object to restrict the type of array's elements. If it's not a type of schema or it's not given, it will be ignored, which means elements of the array can be any type.

Example

const schema1 = racoon.array();
schema1.validate(1); // fail
schema1.validate({}); // fail
schema1.validate([1, 'a', {}]); // pass

const schema2 = racoon.array(
  racoon.number()
);
schema2.validate(['a', 'b']); // fail
schema2.validate([1, 2]); // pass

Last updated