map()
map():方法返回一個新數(shù)組,數(shù)組中的元素為原始數(shù)組元素調(diào)用函數(shù)處理后的值
案例:
const data = res.map(item => item.id);
const data = res.map(item => return item.id);
const data = res.map(item => { name: item.name, id: item.id })
const data = res.map(item => { text: item.id + item.name });
const data = res.map(item => {
const temp = find(options, { code: item });
return temp;
})
filter()
filter():方法創(chuàng)建一個新的數(shù)組,新數(shù)組中的元素是通過檢查指定數(shù)組中符合條件的所有元素
const arr= [4, 9, 16, 25];
const arr1 = arr.map(item => item+2)
console.log(arr)
console.log(arr1)
注:
foreach遍歷數(shù)組,不會有返回值
map遍歷數(shù)組,返回處理后的新數(shù)組
every判斷數(shù)組中每一個元素是否符合某個條件,返回一個布爾值
some判斷數(shù)組中是否有元素符合某個條件,返回一個布爾值
filter篩選數(shù)組中滿足條件的元素,返回篩選后的新數(shù)組
find:返回符合條件的第一個對象文章來源:http://www.zghlxwxcb.cn/news/detail-687286.html
js遍歷:https://blog.csdn.net/JackieDYH/article/details/118568333文章來源地址http://www.zghlxwxcb.cn/news/detail-687286.html
到了這里,關(guān)于Vue的map()方法和filter()方法的使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!