Simple shortid, uuid (unique id) solution in Javascript

less than 1 minute read

When working for a company or a serious side hustle, probably this should be done via a third party library like However, when just to create some code snippets or some example projects for whatever reason, it’s handy to know and worth to momerise following simple way to generate short unique ids.


This one liner solution is borrowed from:, credits to Martin Braun. I like elegent one liner solutions. Just I changed the argument passed to slice from -6 to 2, which makes it generate a bit longer string (length 11) than shorter one (length 6).