function length
length(x:
string
| number
| array<string | number>
| matrix<string | number>
): number

Gets the length of a vector or the largest array dimension.

Returns the length of a vector or the largest dimension of a 2D array (matrix).

Examples

Length of a 1D array (vector)

import { assertEquals } from "jsr:@std/assert";

assertEquals(length([3, 5, 6]), 3);

Length of a single element (should be 1)

import { assertEquals } from "jsr:@std/assert";

assertEquals(length(5), 1);

Length of a 2D array (matrix)

import { assertEquals } from "jsr:@std/assert";

assertEquals(length([[5, 4], [-1, 2]]), 2);

Empty array (should be 0)

import { assertEquals } from "jsr:@std/assert";

assertEquals(length([]), 0);

Parameters

x:
string
| number
| array<string | number>
| matrix<string | number>

The input array, matrix, or element.

Return Type

number

Returns the length of the vector or the largest dimension of the array/matrix.

Throws

If no arguments are provided.