I have a student participation page that I provide for my students. I currently remove students by utilizing underscore by finding an id and simply removing that student based on the id. How do I go about implementing what I have below in ES6? I would appreciate any advice and or pointers.
var students = [{firstname: 'Jon', id: 99}, {firstname: 'Bob', id: 22}]
students = _.without(students, _.findWhere(students, {
id: 99
}));
That's a simple filter
var students = [{firstname: 'Jon', id: 99}, {firstname: 'Bob', id: 22}] students = students.filter(e => e.id !== 99); console.log(students);
Note that there's not too much ES6 involved here, filter
is available since ES5. The only thing ES6 here is the arrow function.
您正在寻找Array.prototype.filter :
students = students.filter(student => student.id !== 99);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.