“Dapatkan JavaScript ID acak” Kode Jawaban

ID acak JS

var ID = function () {
  // Math.random should be unique because of its seeding algorithm.
  // Convert it to base 36 (numbers + letters), and grab the first 9 characters
  // after the decimal.
  return '_' + Math.random().toString(36).substr(2, 9);
};
Diz Andriana

ID acak JS

Math.random().toString(36).slice(2);
Dotch

Hasilkan JavaScript ID acak

 const makeid = (length) =>  {
        var result           = '';
        var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        var charactersLength = characters.length;
        for ( var i = 0; i < length; i++ ) {
          result += characters.charAt(Math.floor(Math.random() * 
     charactersLength));
       }
       return result;
    }
Sid Potti

Dapatkan JavaScript ID acak

let ID = (length = 6) => {
	// new Date() will return current time
  	// getTime() method returns the number of milliseconds* since the Unix Epoch.
	// -length to get last items on string
	return new Date().getTime().toString().slice(-length);
}
aoneahsan

Jawaban yang mirip dengan “Dapatkan JavaScript ID acak”

Pertanyaan yang mirip dengan “Dapatkan JavaScript ID acak”

Lebih banyak jawaban terkait untuk “Dapatkan JavaScript ID acak” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya