filter 用于对数组的过滤,它会过滤满足的条件并返回一个新数组。举例
let arr=[{name:'zs',age:12},{name:'ls',age:12},{name:'ww',age:12},{name:'zl',age:12}]
/* 举例一*/
arr.filter(item=> item.name=='zs') //过滤满足name == ‘zs’的项
arr=[{name:'zs',age:12}] //返回的是一个新数组
/* 举例二*/
arr.filter(item=> item.name!='zs')
arr=[{name:'ls',age:12},{name:'ww',age:12},{name:'zl',age:12}] //返回的是一个新数组
应用场景:如删除列表等