Nodeschool Public Materials

    random-from-array
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    Written in TypeScript npm Build Status

    TypeScript module with type definition support by default. Also works with other JavaScript projects.

    random-from-array

    Given an array, return a random value from it.

    Useful when

    An array of elements must output a random value.

    Installation

    $ npm i random-from-array

    Usage

    Try it on CodeSandbox

    import randomFromArray from 'random-from-array'
     
    randomFromArray(['bossa nova', 'jazz', 'rock']) // one of: 'bossa nova' or 'jazz' or 'rock'
     
    // also works with an array of objects
    const arrayOfObj = [
      { value: 'bossa nova' },
      { value: 'jazz' },
      { value: 'rock' }
    ]
     
    randomFromArray(arrayOfObj) // one of: { value: 'bossa nova' } or { value: 'jazz' } or { value: 'rock' }

    License

    random-from-array © Cezar Augusto. Released under the MIT License.

    Install

    npm i random-from-array

    DownloadsWeekly Downloads

    5

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    5.65 kB

    Total Files

    11

    Last publish

    Collaborators

    • cezaraugusto