📚Cheatsheets

Cheatsheet collection for go, rust, python, shell and javascript.

Generate Random String in JavaScript

Generate random string.

function generate(length, defaultVal = "") {
    let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_{}/";
    Array(length).fill(0).forEach(() => {
    	 defaultVal += letters[Math.floor(Math.random() * 64)];
    })
    return defaultVal;
}

Usage:

console.log(generate(32));