
es6
AI前端高级工程师
不忘初心,砥砺前行
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
计算数组最大值
利用apply()方法的第一个参数可以改变this的指向,第二个参数是数组的形式,来完成这一需求。Math.max.apply(null, arr) 既然apply()方法可以使用,那么我们也可以使用call()方法,并配合扩展运算符使用。Math.max.call(null, ...arr) ...原创 2021-04-30 18:37:34 · 494 阅读 · 0 评论 -
数组修改、判断是否包含、过滤、判断短路
1、this.$set【修改数组】this.$set(this.trains, this.snapIndex, newObj);2、includes【直接返回true、false比较方便、NaN也可以比较】["TT", "TB", "TF", "BT", "FT"].includes(this.transferType)3、数组过滤let othseat = ticketArr.filter(r => r.seatName !== "无座");4、数组短路逻辑 i.原创 2021-04-30 18:41:44 · 183 阅读 · 0 评论 -
对象合并使用扩展运算符...运用场景【后台传参】、object.assign运用场景【配合数组遍历再合并对象】
1、对象扩展运算符...【后台传参】et fast = { ...res.data.product, title: res.data.name, buttonName: res.data.buttonName, // price: res.data.price,原创 2021-04-28 14:42:19 · 250 阅读 · 0 评论 -
es6中forEach和map的使用区别
1、需要改变数组使用forEachseats.forEach((com, i) => { com.fastPack = fastPacks[i]; // 注入成功率 两程座席类型的成功率 let firstRate = (com.firstSeat.probability || 0) * 1; let secondRate = (c.原创 2021-04-28 14:28:44 · 666 阅读 · 0 评论 -
es6数组中寻找index、页面高度分成数组、监听滚动状态
// 计算得到当前分类的下标 currentIndex() {// 初始和相关数据发生了变化 // 得到条件数据 const {scrollY, tops} = this // 根据条件计算产生一个结果 const index = tops.findIndex((top, index) => { // scrollY>=当前top && scrollY<下一个top .原创 2020-12-30 19:19:47 · 536 阅读 · 1 评论 -
es6中经典面试题set应用【数组去重操作】
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Set</title></head><body> <script type="text/javascript"> // const s1 = new Set(); // console.log(s1.size) // const s2 =.原创 2020-09-22 20:30:20 · 252 阅读 · 0 评论 -
es6判断字符串开头和结尾
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>startsWith方法和endsWith方法</title></head><body> <script type="text/javascript"> let str = 'Hello ECMAScript 2015'; let r1 = s.原创 2020-09-22 20:27:53 · 1724 阅读 · 0 评论 -
es6中数组高级方法find,findIndex,includes【查找数组中第一个符合条件的值和该值的索引、数组中是否包含某值】
find,findIndex【查找数组中第一个符合条件的值和该值的索引】<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>find方法</title></head><body> <script type="text/javascript"> var ary = [{ id: 1, .原创 2020-09-22 20:23:14 · 2864 阅读 · 0 评论 -
es6数组过滤方法大全
es6 filter() 数组过滤方法总结1.创建一个数组,判断数组中是否存在某个值var newarr = [ { num: 1, val: 'ceshi', flag: 'aa' }, { num: 2, val: 'ceshi2', flag: 'aa2' }]console.log(newarr.filter(item => item.num===2 ))...原创 2019-08-14 15:02:27 · 2095 阅读 · 0 评论