Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
p => p.id !== id
I was following along until this argument passed to the filter method.
.filter(p => p.id !== id)
Can someone elaborate on this?
stjarnanFront End Web Development Techdegree Graduate 56,488 Points
You're probably using .filter on an array of objects? Correct?
In this case filter takes your array and goes through each item (which you call p in your parameter), checking the items(p) to see if that particular item has got a key called id that doesn't match with whatever your id variable consists of.
Basically, your array contains objects with the key 'id'. Every item your filter goes through will be called 'p' in your function. And that function will see if the current item contains an id (p.id) that doesn't match (!==) with whatever you have stored in your id variable.
I'm writing this in a hurry before going to the gym, tried to make it easy but might have made it hard for you to understand. Does it help you?
As you probably noticed, the
.filter function accepts a function as an argument (MDN Doc on .filter), and then returns a new array with ONLY the filtered items matching the criteria in the function passed as the argument
I would recommend that you watch this 8-min video on the arrow syntax in ES6: https://teamtreehouse.com/library/introducing-arrow-function-syntax
It should help you give a better understanding of what
p => p.id !== id means
Spoiler: It basically is same as:
return p.id !== id
// with the `this` context bound from the parent