<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()方法,返回符合条件的新数组,
适用于筛选符合某个条件要求并不会改变原数组的应用