最近在封装一个基于Vue的vue-task-node组件,文章也就停了几天,之后继续
vue-task-node
https://github.com/Liwengbin/vue-task-node-11x
1.Array数组的遍历方法有哪些?
①结合第10天的内容 (普通for循环、for-in、for-of、forEach)👉juejin.cn/post/684490…
② 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