Reputation: 882
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
}));
Upvotes: 0
Views: 155
Reputation: 73241
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.
Upvotes: 2
Reputation: 3331
You are looking for Array.prototype.filter:
students = students.filter(student => student.id !== 99);
Upvotes: 2