Returns true if the prefix array appears at the start of the source array, false otherwise.
true
false
The complexity of this function is O(prefix.length).
O(prefix.length)
Source array to check.
Prefix array to check for.
true if the prefix array appears at the start of the source array, false otherwise.
import { startsWith } from "@std/bytes/starts-with";import { assertEquals } from "@std/assert";const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);const prefix = new Uint8Array([0, 1, 2]);assertEquals(startsWith(source, prefix), true); Copy
import { startsWith } from "@std/bytes/starts-with";import { assertEquals } from "@std/assert";const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);const prefix = new Uint8Array([0, 1, 2]);assertEquals(startsWith(source, prefix), true);
Returns
trueif the prefix array appears at the start of the source array,falseotherwise.The complexity of this function is
O(prefix.length).