Skip to main content
Module

std/bytes/repeat.ts>repeat

The Deno Standard Library
Latest
function repeat
import { repeat } from "https://deno.land/std@0.224.0/bytes/repeat.ts";

Returns a new byte slice composed of count repetitions of the source array.

Examples

Basic usage

import { repeat } from "https://deno.land/std@0.224.0/bytes/repeat.ts";

const source = new Uint8Array([0, 1, 2]);

repeat(source, 3); // Uint8Array(9) [0, 1, 2, 0, 1, 2, 0, 1, 2]

repeat(source, 0); // Uint8Array(0) []

repeat(source, -1); // Throws `RangeError`

Parameters

source: Uint8Array

Source array to repeat.

count: number

Number of times to repeat the source array.

Returns

Uint8Array

A new byte slice composed of count repetitions of the source array.