ES6
嗒_嗒嗒
这个作者很懒,什么都没留下…
展开
-
ES6 filter的使用场景
1.有一个对象数组A,获取数组中指定类型的对象放到B数组中// ES6var products = [{ name: "苹果", type: "水果"}, { name: "西蓝花", type: "蔬菜"}, { name: "菠萝", type: "水果"}];var newProducts = products.filter(function(pro){ return pro.type === "蔬菜"})console.log(newProducts);原创 2021-04-09 19:13:47 · 178 阅读 · 0 评论 -
ES6 map的使用场景
map需要返回值,如果不给return,默认返回undefinedmap返回的是一个新的数组1.拷贝时改变值例如:有一个数值数组A,将A数组中的值以双倍的形式放到B数组中ES6var arr = [1, 2, 3];var newArr = arr.map(function (num) { return num * 2;})console.log(arr); //[1, 2, 3]console.log(newArr); //[2, 4, 6]// ES5var原创 2021-04-09 18:12:26 · 624 阅读 · 0 评论 -
ES6中数组的forEach() 、map()、filter()、reduce()、some()、every()的用法
一、forEach()循环数组 //ES5 var arr = [1,2,3,4,5,] ;arr.forEach(function(item,index,arr){ console.log(item);}); //ES6var arr = [1, 2, 3, 4, 5];arr.forEach((item,index,arr) => { console.log(item) //结果为1,2,3,4,5})forEach方法中的function原创 2020-07-10 10:09:07 · 773 阅读 · 0 评论