“Hasilkan ID JavaScript Unik” Kode Jawaban

Hasilkan ID JavaScript Unik

var uniq = 'id' + (new Date()).getTime();
Better Badger

JavaScript menghasilkan ID unik

function randomId(): string {
  const uint32 = window.crypto.getRandomValues(new Uint32Array(1))[0];
  return uint32.toString(16);
}
faisalqureshi

Hasilkan ID JavaScript Unik

function uuid() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
    return v.toString(16);
  });
}

var userID=uuid();//something like: "ec0c22fa-f909-48da-92cb-db17ecdb91c5" 
Grepper

Cara Menghasilkan ID Unik di Node JS

// The fastest possible way to create random 32-char string in Node is 
// by using native crypto module:

const crypto = require("crypto");

const id = crypto.randomBytes(16).toString("hex");

console.log(id); // => f9b327e70bbcf42494ccb28b2d98e00e
Computer Nerd

ID string unik JS

const uid = () => {
  return Date.now().toString(36) + Math.random().toString(36).substr(2);
};

// Usage. Example, id = khhry2hb7uip12rj2iu
const id = uid();
abdelghanyMh

Jawaban yang mirip dengan “Hasilkan ID JavaScript Unik”

Pertanyaan yang mirip dengan “Hasilkan ID JavaScript Unik”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya