Comment on page


Check the length of a value
This comparison verifies the length of a given object. This includes Array, TypedArray, ArrayBuffer, and custom classes that have a length property.
class LengthExample {
constructor(public length: i32 = 0) {}
const array = new Array<Vec3>(100);
const typedarray = new Uint8Array(42);
const buffer = new ArrayBuffer(29);
const custom = new LengthExample(50);
// Array<T> has a length
// TypedArrays have a length
// ArrayBuffer uses byteLength
// length is defined on LengthExample
If this method is used with anything other than a reference type, it will result in a compile time error.
Note: ArrayBufferclasses are tested using the byteLength property.
This method is safe to use with jest, with the exception of using ArrayBuffer type references.