芹菜是一根葱
专业解决各种前端Bug,吊打各种面试官
 <script>
      const arr = [
        { id: 1, name: "aa", isDone: false },
        { id: 2, name: "bb", isDone: false },
        { id: 3, name: "cc", isDone: true },
        { id: 4, name: "dd", isDone: true },
      ];
      const newArr = arr.filter((item) => {
        // return item.isDone //isDone:true 的新数组
        return !item.isDone; //isDone:false 的新数组
      });
      console.log(newArr);

      const arr1 = [1,23,56,9,877,856,456]
      const newArr1 = arr1.filter ((item)=>{
        return item < 800  //[1, 23, 56, 9, 456]
      })
      console.log(newArr1);
    </script>

 

filter()方法 ,不作用于空数组,

filter()方法,返回符合条件的新数组,

适用于筛选符合某个条件要求并不会改变原数组的应用

posted on 2022-06-06 10:53  芹菜是一根葱  阅读(1248)  评论(0编辑  收藏  举报