I should mention that this will be going into a database so it truly needs to be unique. I need to define the id before it enters the database no questions asked.
for (var i = 0; i < obj.length; i++) {
var id = Date.now();
console.log(id);
}
The problem is, this is the output:
1428356251606
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
1428356251607
...
I was thinking of using Math.random()
but it might in the name of all the Norse gods actually hit the same number twice.
Any idea of how to make this truly unique while sustaining the speed of the for loop?