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

x/ayonli_jsext/array/index.ts>random

A JavaScript extension package for building strong and modern applications.
Latest
function random
import { random } from "https://deno.land/x/ayonli_jsext@v0.9.72/array/index.ts";

Returns a random element of the array, or undefined if the array is empty.

Examples

Example 1

import { random } from "@ayonli/jsext/array";

const arr = [1, 2, 3, 4, 5];

console.log(random(arr)); // 3 for example

console.log(random(arr, true)); // 3 for example
console.log(arr); // [1, 2, 4, 5]

Parameters

arr: T[]

If true, the element will be removed from the array.

optional
remove = [UNSUPPORTED]

Returns

T | undefined