Skip to main content
Version: Next

getRandomValue

Using

Function selects random items from array, object, map, set. If a primitive, it just returns the primitive as it is.

Demo - use JSON
getRandomValue(
)
3

Arguments

ArgumentTypeDescriptionExample
inputanyCan be any type["Array"]
{ name: "Alina" }
new Map()
14

Returns

any — selected random value from input or input for primitive.

Examples

getRandomValue([1, 2, 3]);
// 2

getRandomValue([1, 2, 3]);
// 3

getRandomValue({ name: 'Alina', age: 20, sex: 'w' });
// "Alina"

getRandomValue({ name: 'Alina', age: 20, sex: 'w' });
// 20

getRandomValue(66);
// 66

getRandomValue('text');
// "text"

Resources

📦 Since:1.2.0
📦 Last updated:1.2.0
📦 Available in:1.3.0