摘要: let index = 0; const mapTree = (org) => { const haveChildren = Array.isArray(org.children) && org.children.length > 0; index++; return { ...org, sortL 阅读全文
posted @ 2022-03-18 17:01 阿清吖 阅读(1362) 评论(0) 推荐(0)
摘要: /** * 拆分数组 * @param {Array} arr 原数组 * @param {Number} len 拆分长度 * @returns {Array} */ 1、for循环 + slice function subGroup(arr, len) { var newArr = []; fo 阅读全文
posted @ 2021-09-14 16:40 阿清吖 阅读(2049) 评论(0) 推荐(0)
摘要: 我们先声明一个为[3, 5, 8, null, 'qwe', 5, 2, 6, 4, 'qwe', 3, 5, 2, 42, 42, 8, 56, null, 56, 56, 6]的数组,然后利用下面方法实现去除重复项。 const arr = [3, 5, 8, null, 'qwe', 5, 2 阅读全文
posted @ 2021-09-07 10:18 阿清吖 阅读(266) 评论(0) 推荐(0)
摘要: 1、获取文件后缀名 使用场景:上传文件判断后缀名 /** * 获取文件后缀名 * @param {String} filename */ export function getExt(filename) { if (typeof filename == 'string') { return file 阅读全文
posted @ 2021-09-06 15:35 阿清吖 阅读(73) 评论(0) 推荐(0)
摘要: 下载含有url的文件: function downloadUrlFile(url, fileName) { const url2 = url.replace(/\\/g, '/'); const xhr = new XMLHttpRequest(); xhr.open('GET', url2, tr 阅读全文
posted @ 2021-08-20 17:09 阿清吖 阅读(671) 评论(0) 推荐(0)
摘要: 判断是否是IE: function isIE() { const userAgent = window.navigator.userAgent; // 取得浏览器的userAgent字符串 const isIE = userAgent.indexOf('compatible') > -1 && us 阅读全文
posted @ 2021-08-20 17:02 阿清吖 阅读(404) 评论(0) 推荐(0)
摘要: 数据例子: let ary = [{name: '1', child: [{id: 1, label: '1'}, {id: 2, label: '2'}]}, {name: '2', child: [{id: 3, label: '3'}, {id: 4, label: '4'}]}] 递归方法: 阅读全文
posted @ 2021-08-20 16:39 阿清吖 阅读(232) 评论(0) 推荐(0)
摘要: ECMAScirpt5 中 Array 类中的 filter 方法使用目的是移除所有为 ”false“ 类型元素: var a = [1, 2, "b", 0, {}, "", NaN, 3, undefined, null, 5]; var b = a.filter(Boolean); // [1 阅读全文
posted @ 2021-08-20 14:52 阿清吖 阅读(685) 评论(0) 推荐(0)