Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Get random name from an array in javascript

function randomFunc(names) {
    for (let i = 0; i < 2; i++) {
        const random = names[Math.floor(Math.random() * names.length)];
        return random
    }
}
const names = ["Abir", "Arham", "Sadi", "Labi", "Mahdi"]
console.log(randomFunc(names));
 
PREVIOUS NEXT
Tagged: #Get #random #array #javascript
ADD COMMENT
Topic
Name
7+7 =