直接進入寫法及範例
const dataList = [5, 7, 10, 99];
const newDataList = dataList.filter(function(item){
return item >= 10;
});
console.log(newDataList);
執行結果
const dataList = ['food', 'good', 'english', 'cat'];
const newDataList = dataList.filter(function(item){
return item.length === 3;
});
console.log(newDataList);
執行結果
const dataList = [
{
goodsName: '帆布提袋',
price: 499
},
{
goodsName: '文青斜背包',
price: 399
},
{
goodsName: '簡約風飲料提袋',
price: 39
},
]
const newDataList = dataList.filter(function(item){
return item.price > 200;
});
console.log(newDataList);
執行結果
const dataList = [5, 7, 10, 99];
const newDataList = dataList.filter((item) => {
return item >= 10;
});
console.log(newDataList);
const dataList = [5, 7, 10, 99];
const newDataList = dataList.filter(item => item >= 10);
console.log(newDataList);
雙十連假還是要努力學習!
這是我的學習紀錄,我們下次見 ~