Array.prototype.map()和Array.prototypefilter()

ES5 => 筛选功能  Array.prototypefilter():
代码:
var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(word => word.length > 6);

console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]

 

 
ES5 => 数组的处理 Array.prototype.map()
代码:
var array1 = [1, 4, 9, 16];

// pass a function to map
const map1 = array1.map(x => x * 2);

console.log(map1);
// expected output: Array [2, 8, 18, 32]

 

 
 
 
 
 

 

posted @ 2018-01-16 15:08  Chen,ChunChang  阅读(306)  评论(0编辑  收藏  举报