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 :: close alert after 5 seconds javascript 
Javascript :: js count char frequency in string 
Javascript :: inline style react with true or false 
Javascript :: react declare multiple states 
Javascript :: install specific version of npm for your project 
Javascript :: regrex match emails 
Javascript :: convert date dd/mm/yyyy to date object js 
Javascript :: jquery select dropdown 
Javascript :: phone number with dashes 
Javascript :: JavaScript string encryption and decryption 
Javascript :: TypeError: Class constructor Model cannot be invoked without 
Javascript :: nodejs spawn set env variable 
Javascript :: condition inner populate mongoose 
Javascript :: liquid object 
Javascript :: bcrypt nodejs hash password 
Javascript :: nodejs express server img src 
Javascript :: javascript for loop array 
Javascript :: javascript resize window 
Javascript :: js returns the number of true values there are in an array 
Javascript :: mobile number validation in javascript with country code 
Javascript :: click on button submitting the form in angular 
Javascript :: how to add a picker in expo 
Javascript :: how to get last child element in javascript 
Javascript :: javascript factorial of a number 
Javascript :: jquery multiple div click 
Javascript :: javaScript getDay() Method 
Javascript :: my vscode does not recognize react code syntax 
Javascript :: how to get updated data-value in jquery 
Javascript :: mutable array methods in javascript 
Javascript :: js combine 2 array to object key value 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =