使用這些單行程式碼將您的 JavaScript 技能提升到全新水平,這也將節省您很多開發時間 🚀
原文出處:https://dev.to/nfrankel/20-killer-javascript-one-liners-thatll-save-you-hours-of-coding-o14
Math.max(...array)
[...new Set(array)]
Math.floor(Math.random() * 100) + 1
!isNaN(parseFloat(string))
new Date().toString()
Array.isArray(variable)
typeof variable === "object"
array.join(",")
typeof variable === "function"
Object.values(object)
array.filter(x => x === element).length
{ [key]: value }
string === string.split("").reverse().join("")
array.reduce((a, b) => a + b, 0));
Date.now()
variable === null
typeof variable === "undefined"
Math.min(...array)
array.length === 0
Array.from({ length: n }, (_, i) => i)
以上簡單分享,希望對您有幫助!