Hi, I must admit I don’t know much javascript, but I seem to be doing ok with the react course. But I am having some trouble understanding this code from the todo list project.
Here
The code is:
var filteredItems = this.state.items.filter(function (item) {
return (item.key !== key);
});
I understand it gets the clicked item from the user and compares that item from the list of items and returns a list without that item effectively removing it. I’m just having trouble understanding the syntax. I don’t understand specifically this part:
(function (item) {
return (item.key !== key);
});
What is function item? how are we getting keys from it and what key are we comparing it to? Thanks
And a little bonus question. If I’m understanding the => operator correctly then can it be written like this?
var filteredItems = this.state.items.filter((item) => {
return (item.key !== key);
});