1

How to create a UUID in JavaScript

 2 years ago
source link: https://www.wisdomgeek.com/development/web-development/javascript/how-to-create-a-uuid-in-javascript/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Creating a globally unique identifier has always been a necessity in all programming languages and for some reason, JavaScript never had a way of doing it in the default spec. But that is changing now with the crypto API. We can now create a UUID in JavaScript.

What is UUID/GUID?

A universally unique identifier (UUID) is a 128-bit label used for information in computer systems. The term globally unique identifier (GUID) is also used instead of UUID.

- Advertisement -

For example: “4ab4e2a1-0efb-4e5b-8f73-e503f5b8e89f”

Create a UUID in JavaScript

Traditionally, we needed to use either Math.Random(), or the Date object and then convert it into a UUID format. But now all we need is:

crypto.randomUUID() // "819df8d4-587b-4200-90b3-d30f8ed01457"

It is important to note that it still might not generate a unique value though the probability of that happening is fairly low.

Share

How to create a UUID in JavaScript

JavaScript

Modified date: September 30, 2021

Creating a globally unique identifier has always been a necessity in all programming languages and for some reason, JavaScript never had a...

How to convert a React component to an image

React

Modified date: September 27, 2021

Sometimes you want to give the users the ability to download a part of the web application as an image. In that...

Specifying a node version in Repl.it

JavaScript

Modified date: September 13, 2021

I was recently trying to use a later version of Node on Repl.it. I wanted to use a package that supported ES...

Accessing the clipboard in JavaScript

JavaScript

Modified date: September 8, 2021

Developers are probably the laziest people on the planet. And of all the things, copy-paste is our favorite keyboard shortcut. But what...

Using counters in CSS to number elements automatically

Web Development

Modified date: August 31, 2021

Ordered lists have been an important part of web design for quite a while now. If we needed more control over the...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK