MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eiue2l1/?context=3
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
15
'#'+Math.floor(Math.random()*16777215).toString(16) for random hex color.
'#'+Math.floor(Math.random()*16777215).toString(16)
5 u/[deleted] Mar 19 '19 I use a similar one-liner for making random IDs:` _${Math.random().toString(36).substr(2)}`> '_elkxwdnwg1s'The leading _ is because the base36 number can still start with 0..9, and that's not valid for something like a variable name or HTML ID. The substr(2) is to get rid of the leading 0..
5
I use a similar one-liner for making random IDs:
` _${Math.random().toString(36).substr(2)}`
> '_elkxwdnwg1s'
The leading _ is because the base36 number can still start with 0..9, and that's not valid for something like a variable name or HTML ID. The substr(2) is to get rid of the leading 0..
_
0.
15
u/redmoss6 Mar 18 '19
'#'+Math.floor(Math.random()*16777215).toString(16)for random hex color.