javascript數(shù)組中的map方法和filter方法
一、map方法
1編輯器
編輯器搞出來 一起研究研究數(shù)組中的map方法:
2代碼部分
var geyao=['歌謠',"很帥","很強"] ? ? geyao.map((currentValue,index,arr,thisValue)=>{ ? ? ? ? console.log(currentValue,"currentValue") ? ? ? ? console.log(index,"index") ? ? ? ? console.log(arr,"arr") ? ? ? ? console.log(thisValue,"thisValue") ? ? })
3運行結果
小結:
currentvalue
當前元素的值 index 索引值 arr 當前元素屬于的數(shù)組對象 thisValue 對象作為該執(zhí)行函數(shù)的回調
二、filter方法
1編輯器
編輯器搞出來 一起研究研究數(shù)組中的map方法:
2代碼
var geyao=['歌謠',"很帥","很強"] ? var geyao1 = geyao.filter((currentValue,index,arr,thisValue)=>{ ? ? ? ? console.log(currentValue,"currentValue") ? ? ? ? console.log(index,"index") ? ? ? ? console.log(arr,"arr") ? ? ? ? console.log(thisValue,"thisValue") ? ? ? ? return currentValue==='歌謠' ? ? }) ? ? console.log(geyao1,"geyao1")
3運行結果
小結:
currentvalue
當前元素的值 index 索引值 arr 當前元素屬于的數(shù)組對象 thisValue 對象作為該執(zhí)行函數(shù)的回調 形成一個新數(shù)組 形成的是過濾后的值 和map相似
到此這篇關于javascript數(shù)組中的map方法和filter方法的文章就介紹到這了,更多相關map和filter方法內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
如何使用proxy實現(xiàn)一個簡單完整的MVVM庫的示例代碼
這篇文章主要介紹了如何使用proxy實現(xiàn)一個簡單完整的MVVM庫的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-09-09JS自定義函數(shù)對web前端上傳的文件進行類型大小判斷
這篇文章主要介紹了JS自定義函數(shù)對web前端上傳的文件進行類型大小判斷的相關資料,需要的朋友可以參考下2016-10-10使用Javascript和DOM Interfaces來處理HTML
使用Javascript和DOM Interfaces來處理HTML...2006-10-10javascript 瀏覽器判斷 綁定事件 arguments 轉換數(shù)組 數(shù)組遍歷
javascript 瀏覽器 判斷 綁定事件 arguments 轉換數(shù)組 數(shù)組遍歷等函數(shù)2009-07-07