1.数组去重
function dedupe(array) {
return Array.from(new Set(array));
}
let arr = [3, 5, 2, 2, 5, 5];
let unique = [...new Set(arr)];
2.获取url参数
function getQuery(paramName, defaultValue) {
var reg = new RegExp("(^|&)" + paramName + "=([^&]*)(&|$)"); // 匹配目标参数
var result = window.location.search.substr(1).match(reg); // 对querystring匹配目标参数
if (result != null) {
return decodeURIComponent(result[2]);
} else {
return defaultValue;
}
}
3.生成36位GUID
function getGuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}