Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
function startsWith
import { startsWith } from "https://deno.land/x/embassyd_sdk@v0.3.4.0.0-alpha2/lib/esm/deps/deno.land/std@0.140.0/bytes/mod.js";

Returns true if the prefix array appears at the start of the source array, false otherwise.

The complexity of this function is O(prefix.length).

import { startsWith } from "./mod.ts";
const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
const prefix = new Uint8Array([0, 1, 2]);
console.log(startsWith(source, prefix)); // true

Parameters

source
prefix