M
M
Michael Someone2021-05-31 15:22:59
Node.js
Michael Someone, 2021-05-31 15:22:59

How can I output random lines in a variable to the console?

var abra = ["ABC", "Babylka", "Doctor", "Hospital", "IT", "DataBase", "AbrakaDabra", "Bye", "Hi", "Alphabet", "Da", "No", "Yes"]

I have a variable abra (no other name came to mind).
I need to output 10 random lines to the console from there,
like: console.log(abra)
But so that when I run the script, it gives me other random lines from there

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-05-31
@TrotorNo

This will output one value. Then add yourself.

const abra = ["ABC", "Babylka", "Doctor", "Hospital", "IT", "DataBase", "AbrakaDabra", "Bye", "Hi", "Alphabet", "Da", "No", "Yes"]
const random = Math.floor(Math.random() * abra.length);
console.log(random, abra[random]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question