javascript的ES6学习总结(第二部分)
1. 数组循环 介绍数组循环之前,先回顾一下ES5数组的循环 (1)数组遍历(代替普通的for):arr.forEach(callback(val,index,arr){todo}) //val是数组的当前项,index是数组的键名(下标),arr是整个数组 let arr = ['today','tomorrow','the day after tommrrow','three days from now' ]; arr.forEach( function (val,index,arr){ console.log(val,index,arr); // today 0 (4) ["today", "tomorrow", "the day after tommrrow", "three days from now"]... }); (2)数组映射:arr.map(callback(item,index,arr){todo... 正常情况下,需要配合return,返回的是一个新数组,若没有return,相当于forEach,一般用于在有return的情况下}) //item是数组的当前项,index是数组的键名(下标),arr是整个数组 let arr = [ {title: 'aaaa',read:100,hot: true }, {title: 'bbbb',read:100