最近在封裝一個基於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
複製代碼