Sometimes, we want to generate a short UID like "aX4j9Z" in JavaScript
In this article, we’ll look at how to generate a short UID like "aX4j9Z" in JavaScript.
How to generate a short UID like "aX4j9Z" in JavaScript?
To generate a short UID like "aX4j9Z" in JavaScript, we can use the nanoid
package.
To install it, we run
npm i nanoid
Then we write
import { nanoid } from "nanoid";
console.log(nanoid(11));
to call nanoid
with 11 to return a random string with 11 characters.
Conclusion
To generate a short UID like "aX4j9Z" in JavaScript, we can use the nanoid
package.