摘要: ES6之数组的map、reduce操作 类比:java中的lamdba表达式中的map和reduce 1、map():接收一个函数,将原数组中的所有元素用这个函数处理之后放入新的数组返回 let arr=[3,20,-15,5]; // arr = arr.map((item)=>{ // retu 阅读全文
posted @ 2022-04-14 17:27 LZ1024 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 1、获取对象的键、值、键-值 // const person={ // name:'jack', // age:21, // language:['java','js','css'] // } // console.log(Object.keys(person)); //获取对象的所有key // 阅读全文
posted @ 2022-04-14 17:25 LZ1024 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 1.函数参数默认值设置 在ES6以前我们无法为函数参数设置默认值,只能采用变通写法 function add(a,b) { b=b || 1; return a+b; } console.log(add(10)); 使用ES6新的语法规则,给参数B设置默认值 function add(a,b =1) 阅读全文
posted @ 2022-04-14 17:19 LZ1024 阅读(31) 评论(0) 推荐(0) 编辑
摘要: 1、字符串之常用函数 let str='hello.vue'; console.log(str.startsWith('hello')); //true console.log(str.endsWith('vue')); //true console.log(str.includes('hello' 阅读全文
posted @ 2022-04-14 17:12 LZ1024 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 1.数组解构 以前我们要获取数组中的元素时这样的 let arr =[1,2,3]; let a=arr[0]; let b=arr[1]; let c=arr[2]; console.log(a,b,c); 现在我们可以使用数组解构来简化代码 let arr =[1,2,3]; let [a,b, 阅读全文
posted @ 2022-04-14 17:10 LZ1024 阅读(44) 评论(0) 推荐(0) 编辑