创建过去七天的数组
[...Array(7).keys()].map(days => new Date(Date.now() - 86400000 * days));
生成随机ID
Math.random().toString(36).substring(2);
获取URL的查询参数
?foo=bar&baz=bing => {foo: bar, baz: bing}
q={};
location.search.replace(/([^?&=]+)=([^&]+)/g, (_,k,v) => q[k]=v);
console.log(q)
实时更新时间
document.body.onload = () => {
// Chrome
setTimeout(() => document.body.innerHTML = new Date().toLocaleString().slice(10, 19))
}
数组混淆
let a = (arr) => arr.slice().sort(() => Math.random() - 0.5)
let b = a([1,2,3,4,5,])
console.log(b)
生成随机十六进度(颜色值)
'#' + Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, '0')
写出运行结果
for(i=0;++i<101;console.log(i%5?f||i:f+'Buzz'))f=i%3?'':'Fizz'
数组去重
[...new Set(arr)]
创建特定长度的数组
[...Array(3).keys()]
// [0, 1, 2]
返回一个键盘
(_=>[..."`1234567890-=~~QWERTYUIOP[]\\~ASDFGHJKL;'~~ZXCVBNM,./~"].map(x=>(o+=`/${b='_'.repeat(w=x<y?2:' 667699'[x=["BS","TAB","CAPS","ENTER"][p++]||'SHIFT',p])}\\|`,m+=y+(x+' ').slice(0,w)+y+y,n+=y+b+y+y,l+=' __'+b)[73]&&(k.push(l,m,n,o),l='',m=n=o=y),m=n=o=y='|',p=l=k=[])&&k.join`
网友评论