Helpers

randomEl.mjs

@mr_ozio/scraper-utils · v2.5.0 · Generated April 21, 2026

Target Style

Target Style

1 exports

const

pickRandom

Target Style
export const pickRandom = ({ from }) => from[Math.floor(Math.random() * from.length)]

Picks a random element using named options.

Target style API. Preferred for new code.

Parameters

  • options{ from: T[] }

Returns

T | undefined

Example

const winner = pickRandom({
  from: ['a', 'b', 'c'],
})

Legacy Style

Legacy Style

1 exports

const

randomEl

Legacy Style
export const randomEl = (arr) => pickRandom({ from: arr })

Returns a random element from an array.

Legacy API. Kept for older code and not the preferred choice for new code.

Parameters

  • arrT[]

Returns

T | undefined