Skip to content

8 Dec 2011 by Nomad

Snippets: Unique Id

A very simple function for creating a unique id in JavaScript.

function uniqueId(len) {
	var tokens = "abcdefghijklmnopqrstuvwxyz0123456789".split("");
	var id = "";

	for(var i = 0; i < len; i++)
		id += tokens[Math.floor(Math.random() * tokens.length)];

	return id;
}