随笔分类 -  JS常用方法集锦

摘要:JS终止 for 循环 throw new Error(""); 阅读全文
posted @ 2022-04-08 16:31 SaBoo 阅读(317) 评论(0) 推荐(0)
摘要://JS 获取最后一个 指定字符 后面的值 function getValue(url){ //获取最后一个/的位置 var site = url.lastIndexOf("\/"); //截取最后一个/后的值 return url.substring(site + 1, url.length); 阅读全文
posted @ 2022-03-17 17:09 SaBoo 阅读(3008) 评论(0) 推荐(0)
摘要:/** * 树转数组扁平化结构 * 深度优先遍历 堆栈 后进先出 */ function deep(node){ let stack = node, data = []; while(stack.length != 0){ let pop = stack.pop(); data.push({ id: 阅读全文
posted @ 2021-08-20 14:25 SaBoo 阅读(823) 评论(0) 推荐(0)
摘要:let arr =[ {id:2,name:'部门1',parentId:0}, {id:3,name:'部门2',parentId:1}, {id:1,name:'部门3',parentId:2}, {id:4,name:'部门4',parentId:1}, {id:5,name:'部门5',pa 阅读全文
posted @ 2021-08-20 14:24 SaBoo 阅读(456) 评论(0) 推荐(0)
摘要:/** * 获取 url 里面的参数 * @param {string} url * @returns {Object} */ export function getQueryObject(url) { url = url == null ? window.location.href : url c 阅读全文
posted @ 2020-11-27 16:30 SaBoo 阅读(83) 评论(0) 推荐(0)
摘要:/** * 函数防抖 * @param {Function} func * @param {number} wait * @param {boolean} immediate * @return {*} */ export function debounce(func, wait, immediat 阅读全文
posted @ 2020-11-27 16:22 SaBoo 阅读(86) 评论(0) 推荐(0)
摘要:/** * 获取随机唯一字符串 * @returns {string} */ export function createUniqueString() { const timestamp = +new Date() + '' const randomNum = parseInt((1 + Math. 阅读全文
posted @ 2020-11-27 16:15 SaBoo 阅读(513) 评论(0) 推荐(0)
摘要:/** * 深拷贝 * @param {Object} source * @returns {Object} */ export function deepClone(source) { if (!source && typeof source !== 'object') { throw new E 阅读全文
posted @ 2020-11-27 16:07 SaBoo 阅读(170) 评论(0) 推荐(0)
摘要:js 获取浏览器名称和版本 function getExplorerInfo() { let explorer = window.navigator.userAgent; explorer = explorer.toLowerCase(); //ie if (explorer.indexOf("ms 阅读全文
posted @ 2020-09-16 17:59 SaBoo 阅读(1003) 评论(0) 推荐(0)