Skip to content

Instantly share code, notes, and snippets.

@eszterkv
Last active September 30, 2017 12:28
Show Gist options
  • Save eszterkv/172a8fd829dd6c609b447bcf710513c9 to your computer and use it in GitHub Desktop.
Save eszterkv/172a8fd829dd6c609b447bcf710513c9 to your computer and use it in GitHub Desktop.
Creates a unique ID in JavaScript
const id = Date.now() + Math.random().toString(16).substr(2);

unique_id.js

Returns a unique alphanumeric ID given that it uses Date.now() and a random string.

Usage

Create and use the id any time.

var yourNewId = Date.now()+Math.random().toString(16).substr(2);
var yourOtherNewId = Date.now()+Math.random().toString(16).substr(2);

yourNewId and yourOtherNewId will look something like this, but of course, both completely unique: "146849867772717a4cb2f"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment