Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/bytes/mod.ts>startsWith

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function startsWith
import { startsWith } from "https://deno.land/std@0.197.0/bytes/mod.ts";

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 "https://deno.land/std@0.197.0/bytes/starts_with.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: Uint8Array
prefix: Uint8Array

Returns

boolean