最好的种树是十年前,其次是现在。歌谣 每天一个前端小知识 提醒你改好好学习了 知乎博主 csdn博主 b站博主  放弃很容易但是坚持一定很酷     我是歌谣 喜欢就一键三连咯 你得点赞是对歌谣最大的鼓励

1前言

在我们的日常开发中 不免会有很多需要处理数据的方法 本节主要说一说filter的使用不多说把代码编辑器打开

2编辑器

3代码

  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")

 4运行结果

5总结

currentvalue 当前元素的值 index 索引值 arr 当前元素属于的数组对象 thisValue 对象作为该执行函数的回调 形成一个新数组 形成的是过滤后的值 和map相似