const data = [
"1. 바나나",
"2. 사과",
"3. 배",
];
function randomValueFromArray(array) {
const random = Math.floor(Math.random() * array.length);
return array[random];
}
let fruit = randomValueFromArray(data);
console.log(fruit);
// Math.floor() : 가장 큰 정수 값을 돌려준다.
// Math.random() : 0~1 까지의 난수 실수 값을 돌려준다.
출처/참고