最近在封装一个基于Vue的vue-task-node组件,文章也就停了几天,以后继续
vue-task-node
https://github.com/Liwengbin/vue-task-node-11xvue
Array.prototype.forEach()
为数组中每一个元素执行的函数var array = ['a', 'b', 'c'];
array.forEach(function(item,index,arr) {
console.log(element);
});
复制代码
Array.prototype.filter()
方法建立一个新数组, 其包含经过所提供函数实现的测试的全部元素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"]
复制代码
Array.prototype.map()
方法建立一个新数组,其结果是该数组中的每一个元素都调用一个提供的函数后返回的结果var array = [1, 4, 9, 16];
// pass a function to map
const map1 = array.map(x => x * 2);
console.log(map1);
// expected output: Array [2, 8, 18, 32]
复制代码
Array.prototype.find()
var array = [5, 12, 8, 130, 44];
var found = array.find(function(element) {
return element > 10;
});
console.log(found);
// expected output: 12
复制代码