标签:array tostring nal href class location www 文件夹 cap
// 获取当前路径下?问号后边的值
GetQueryString = function (name) { const reg = new RegExp (`(^|&)${name}=([^&]*)(&|$)`); const href = window.location.href; const index = href.indexOf(‘?‘); const r = href.substr(index + 1).match (reg); if (r != null) return unescape (r[2]); return null; };
调用示例:
获取“https://www.google.com/search?q=baidu” 这个路径 “q” 后面的 “baibu”
templateId(‘q‘);
"baidu"
// 全局唯一ID函数 uuid
GetUuid = function () { return ‘xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx‘.replace (/[xy]/g, c => { let r = (Math.random () * 16) | 0; let v = c == ‘x‘ ? r : (r & 0x3) | 0x8; return v.toString (16); }); }
调用示例:
GetUUid();
"327aaf38-c195-4000-b5c4-d36bf9b2894e"
// 对象数组去重
arrayUnique = function (songs) { const result = {}; const finalResult = []; for (let i = songs.length - 1; i >= 0; i--) { result[songs[i].name] = songs[i]; } Object.keys(result).map((item) => finalResult.push(result[item])); return finalResult; }
// 拉取某个文件夹下面的所有文件
loadAllFile = function (‘filePath‘,‘fileExp‘) { const filesMD = require.context(filePath, true,fileExp); return filesMD.keys(); }
标签:array tostring nal href class location www 文件夹 cap
原文地址:https://www.cnblogs.com/ChineseLiao/p/12979806.html