赋值剪切板
const copyToClipboard = (text) =>
navigator.clipboard?.writeText && navigator.clipboard.writeText(text)
数组去重
const getUnique = (arr) => \[...new Set(arr)\]。
// 测试
const arr = \[1, 1, 2, 3, 3, 4, 4, 5, 5\];
console.log(getUnique(arr))。
滚动到顶部/底部
// 顶部
const scrollToTop = (element) =>
element.scrollIntoView({ behavior: "smooth", block: "start" })
// 底部
const scrollToBottom = (element) =>
element.scrollIntoView({ behavior: "smooth", block: "end" })
标签:片段,const,text,代码,arr,element,clipboard,navigator,js
From: https://www.cnblogs.com/mykai/p/17754076.html