I want to create a 4 digit random word from this array.
const words = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k'];
for that I coded like this..
const word = (
words[Math.floor(Math.random() * 9)] +
words[Math.floor(Math.random() * 9)] +
words[Math.floor(Math.random() * 9)] +
words[Math.floor(Math.random() * 9)]
);
console.log(word) // afab
For this I need to repeat the code words[Math.floor(Math.random() * 9)] again if I need 6 digit or 10 digit.
How can I write the code using a variable that is easy to generate N digit random words without repeat the code?
Thanks in advance