Post

UUID in Javascript

UUID (Universally Unique IDentifier)

1
2
3
4
5
6
7
8
9
10
function uuid() {
  var temp_url = URL.createObjectURL(new Blob());
  var uuid = temp_url.toString();
  URL.revokeObjectURL(temp_url);
  return uuid.substr(uuid.lastIndexOf('/') + 1); // remove prefix (e.g. blob:null/, blob:www.test.com/, ...)
}

for (var i = 0; i < 10; ++i) {
  console.log(uuid());
}

👉 Demo

References

This post is licensed under CC BY 4.0 by the author.