会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
The way of programming
程序之路
博客园
首页
新随笔
联系
订阅
管理
2022年3月18日
JavaScript递归树,修改或添加属性值
摘要: 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)
2021年9月14日
JavaScript之把一个数组按照一定长度分成N份
摘要: /** * 拆分数组 * @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)
2021年9月7日
JavaScript之9种数组去重的方法
摘要: 我们先声明一个为[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)
2021年9月6日
JavaScript之项目中8个必备代码片段
摘要: 1、获取文件后缀名 使用场景:上传文件判断后缀名 /** * 获取文件后缀名 * @param {String} filename */ export function getExt(filename) { if (typeof filename == 'string') { return file
阅读全文
posted @ 2021-09-06 15:35 阿清吖
阅读(73)
评论(0)
推荐(0)
2021年8月20日
JavaScript之H5端根据URL下载文件
摘要: 下载含有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)
JavaScript之PC端根据URL下载文件
摘要: 判断是否是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)
JavaScript之递归遍历数组集合
摘要: 数据例子: 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)
JavaScript之Array.filter(Boolean)
摘要: 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)
公告