标签:alt var pre 匹配 image style filters 取数 color
1.filter的使用场景:假如有一个对象数组A,获取数组中的指定类型的对象放到B数组中
我们在ES5先进行for循环遍历数组,再进行if 判断,如果数组中某个对象的类型符合要求,push 到一个新数组中
var students=[ {name:"vue",type:"lesson"}, {name:"react",type:"lesson"}, {name:"java",type:"lessonone"}, {name:"node",type:"lessonone"}, ]; for(var i=0;i<students.length;i++) { if(students[i].type==="lesson") { filterstudents.push(students[i]); } } console.log(filterstudents);
输出:
在ES6中,
var students=[ {name:"vue",type:"lesson"}, {name:"react",type:"lesson"}, {name:"java",type:"lessonone"}, {name:"node",type:"lessonone"}, ]; filter=students.filter(function(student){ return student.type==="lesson" }); console.log( filter);
输出:
标签:alt var pre 匹配 image style filters 取数 color
原文地址:https://www.cnblogs.com/guangzhou11/p/9630694.html