Categories
JavaScript Answers

How to generate a short UID like “aX4j9Z” in JavaScript?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.