Explanation
So, what I'm doing here is: I'm passing an arrow function to JavaScript's built-in filter()
method on the Array.prototype
object. This arrow function accepts a single argument that I can name anything I like (as long as I don't violate syntax rules of JavaScript). I named the argument person
, since that's what each array item essentially is. Finally, I return the result of running a comparison between each person
object's country
property and the value of 'United States'
.

The ==
operator checks for equality of type, and returns the boolean of true
if the two values match, and the boolean of false
if they do not match. Those person
objects that passed the equality comparison - that is, those person
objects that had the filter's callback function return the boolean of true
after checking for equality between person.country
and 'United States'
- those person objects got pushed into a new array that gets returned from the filter()
method call. Since these return array values do not change the source array in any way - that is, they are "non-destructive" - I had to save them as americans
and brits
- thus, essentially, splitting my source people
array into two distinct subsets based on the country
property of the people
object.