Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Radom String in Javascript

//Can change 7 to 2 for longer results.
let r = (Math.random() + 1).toString(36).substring(7);
console.log("random", r);
 Run code snippet
Comment

Radom String in Javascript

var uuid = require("uuid");
var id = uuid.v4();

// "110ec58a-a0f2-4ac4-8393-c866d813b8d1"
Comment

Radom String in Javascript

// dec2hex :: Integer -> String
// i.e. 0-255 -> '00'-'ff'
function dec2hex (dec) {
  return dec.toString(16).padStart(2, "0")
}

// generateId :: Integer -> String
function generateId (len) {
  var arr = new Uint8Array((len || 40) / 2)
  window.crypto.getRandomValues(arr)
  return Array.from(arr, dec2hex).join('')
}

console.log(generateId())
// "82defcf324571e70b0521d79cce2bf3fffccd69"

console.log(generateId(20))
// "c1a050a4cd1556948d41"
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: js get html content 
Javascript :: javascript how to sort alphabetically 
Javascript :: set cookie and get cookie in javascript 
Javascript :: best and fastest encrypt and decrypt value in javascript 
Javascript :: tolocaledatestring format dd-mm-yyyy 
Javascript :: vue fix eslint error 
Javascript :: firebase timestamp to date angular 
Javascript :: quasar apexchart 
Javascript :: emailjs react npm 
Javascript :: react scroll 
Javascript :: set timeout for loop 
Javascript :: export data to excel using react js 
Javascript :: find input by value attribute javascript 
Javascript :: moment get timezone 
Javascript :: object json parse nestjs 
Javascript :: remove specific element from array javascript 
Javascript :: Javascript removing duplicates in array 
Javascript :: useeffect async await 
Javascript :: number_format in jquery 
Javascript :: diagonal Difference in 2D arrays javascript 
Javascript :: es6 node 
Javascript :: react native share image 
Javascript :: node js check type of variable 
Javascript :: js notifications 
Javascript :: js sum of int in array 
Javascript :: .net mvc javascript function call link 
Javascript :: i18n vue cli 
Javascript :: how to break the foreach loop in javascript 
Javascript :: react slick 
Javascript :: js read xml file 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =