Search
 
SCRIPT & CODE EXAMPLE
 

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));
Comment

how to choose a random name from a list in javascript

function chooseName() {
      let randomName = names[Math.floor(Math.random() * names.length)];
      para.innerHTML = randomName;
    }
    chooseName();
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to create round image in react native 
Javascript :: get user language js 
Javascript :: detect if scrolled to bottom 
Javascript :: title case javascript 
Javascript :: js string only positive float numbers 
Javascript :: setinterval in angular 6 
Javascript :: filter array of objects by another array of objects 
Javascript :: regex a-z javascript 
Javascript :: javascript byte array to hex string 
Javascript :: add class queryselector 
Javascript :: error java.io.filenotfoundexception tessdata/eng.traineddata 
Javascript :: js fake promise with timeout 
Javascript :: parseint array javascript 
Javascript :: three.js create sphere 
Javascript :: js get element padding 
Javascript :: remove last character from string jquery 
Javascript :: javascript search on docuemt for text on iframe 
Javascript :: resolveJsonModule 
Javascript :: console.log object at current state 
Javascript :: node js favicon.ico 
Javascript :: sort date according to months in javascript 
Javascript :: js draw square to canvas 
Javascript :: how to set form control value in angular 
Javascript :: phone number regex angular 
Javascript :: redirect is not defined react/jsx-no-undef 
Javascript :: get buffer from jimp js 
Javascript :: js create element 
Javascript :: search partial string in array javascript 
Javascript :: como deletar node js linux 
Javascript :: javascript object toarray 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =