I'm creating a password generator for learning purposes.
first-input
is my input field where I generate the random string of items in the html.
I'm using a function here because there is a button that triggers it to put the random string of items inside the input field. I found this function in stackoverflow and this function generates 15 random items from the array, but it puts a comma after each item. How do I get rid of the comma? It logs out stuff like:
J,l,9,),6,A,X,e,_,*,[,x,7,1,&
And I need:
Jl9)6AXe_*[x71&
Now, if I want to take a certain number of items from that array without including a specific group of items like capital letters or numbers, or symbols... how would I exclude them from the array? The goal is to check a box and it excludes that group from the generator. Do I split the array somehow? Make multiple arrays that consist of specific symbols only? Is there a simple way to do this?
const characters = [
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"~","`","!","@","#","$","%","^","&","*","(",")","_","-","+","=","{","[","}","]",",","|",":",";","<",">",".","?","/"
];
let firstPass = document.getElementById("first-input");
function firstPassword() {
const shuffledChar = characters.sort(() => 0.5 - Math.random());
const getRandom = (arr, min, max) => {
const numItemsToPick = Math.floor(Math.random() * (max-min+1)) + min
return arr.slice(0, numItemsToPick)
}
firstPass.value = getRandom(shuffledChar, 15,15)
}