1,数组去重
let unique = (arr) => [...new Set(arr)]
console.log(unique(['11','22','33','22']))
//['11','22','33']
2,提取url路径中的参数
getUrlKey:function(name){
return decodeURIComponent((new RegExp('[?|&]'+name+'='+'([^&;]+?) (&|#|;|$)').exec(location.href)||[,""])[1].replace(/\+/g,'%20'))||null;
}
3,判断对象是否为空
let isempty =obj => Reflect.ownKeys(obj).length === 0 && obj.constructor === Object
4,两个日期之间相差的天数
const dayDiff = (date1, date2) => Math.ceil(Math.abs(date1.getTime() - date2.getTime()) / 86400000);
dayDiff(new Date("2021-10-21"), new Date("2022-02-12"))
// Result: 114
5,endswith() 方法,判断字符串是否以指定后缀结尾,如果以指定后缀结尾返回True,否则返回False。可选参数"start"与"end"为检索字符串的开始与结束位置。
校验上传格式可用
let str = '189328dhjkdsk.zip'
str.endsWith('.zip')
//true