Skip to content

Instantly share code, notes, and snippets.

@banhaclong20
Created October 21, 2017 22:55
Show Gist options
  • Save banhaclong20/04667adc1070d09f10c3595fb9beca15 to your computer and use it in GitHub Desktop.
Save banhaclong20/04667adc1070d09f10c3595fb9beca15 to your computer and use it in GitHub Desktop.
Generate Unique Number in JavaScript
function uniqueNumber() {
var date = Date.now();
if (date <= uniqueNumber.previous) {
date = ++uniqueNumber.previous;
} else {
uniqueNumber.previous = date;
}
return date;
}
uniqueNumber.previous = 0;
function ID(){
return uniqueNumber();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment