javascript數組中的map方法和filter方法
一、map方法
1編輯器
編輯器搞出來 一起研究研究數組中的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 當前元素屬于的數組對象 thisValue 對象作為該執(zhí)行函數的回調
二、filter方法
1編輯器
編輯器搞出來 一起研究研究數組中的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 當前元素屬于的數組對象 thisValue 對象作為該執(zhí)行函數的回調 形成一個新數組 形成的是過濾后的值 和map相似
到此這篇關于javascript數組中的map方法和filter方法的文章就介紹到這了,更多相關map和filter方法內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
使用Javascript和DOM Interfaces來處理HTML
使用Javascript和DOM Interfaces來處理HTML...2006-10-10javascript 瀏覽器判斷 綁定事件 arguments 轉換數組 數組遍歷
javascript 瀏覽器 判斷 綁定事件 arguments 轉換數組 數組遍歷等函數2009-07-07