![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
JS工具函数
TheFirstTest
不知所谓小前端
展开
-
js小数指定小数点后位数
常用的截取两位let num = 16.36172;//向下取整Math.floor(num*100)/100;//向上取整Math.ceil(num*100)/100;//四舍五入Math.round(num*100)/100;//四舍五入num.toFixed(2);toFixed(四舍五入)let num = 10.44;console.log(num.toFixed(1));//10.5round(四舍五入)console.log(Math.原创 2022-01-27 11:35:03 · 1084 阅读 · 0 评论 -
sort-对象类数组按指定属性排序
let arr = [ {name: "张三", age: 16}, {name: "李四", age: 17}, {name: "小明", age: 18},];//排序arr.sort((person1, person2) => { const a = person1["age"]; const b = person2["age"]; return b - a;});可根据需要对将排序方法进行封装扩展。let arr = [ .原创 2022-01-27 11:10:50 · 373 阅读 · 0 评论 -
parseTime-时间格式化函数
parseTime(time, pattern) { if (arguments.length === 0 || !time) { console.warn("未传入正确的时间格式:new Date()!"); return null; } const format = pattern || "{y}-{m}-{d} {h}:{i}:{s}"; let date; if (typeof time === "obje.原创 2022-01-24 09:00:17 · 3537 阅读 · 0 评论 -
JS颜色随机生成(rgb、rgba、十六进制、格式转换)
JavaScript颜色,color随机生成转载 2021-12-15 09:38:56 · 5474 阅读 · 0 评论