Small issue in JSON APIs and Ajax: Pre-filter JSON to Get the Data You Need

There is a small issue in JSON APIs and Ajax: Pre-filter JSON to Get the Data You Need challenge in the following part where it said filter out the cat whose “id” key has a value of 1
but the code filter out the cat whose “id” key not has a value of 1
return (val.id !== 1);

Given that the JSON data is stored in an array, you can use the filter method to filter out the cat whose “id” key has a value of 1.

Here’s the code to do this:

json = json.filter(function(val) {
  return (***val.id !== 1***);
});

Hello there,

The text appears to be correct:

you can use the filter method to filter out the cat whose “id” key has a value of 1.

To “filter out” means the same as remove.

The given function:

json = json.filter(function(val) {
  return (val.id !== 1);
});

So, if the id of the val is not equal to 1, return true.

  • If true is returned within a filter, the value is not filtered out
  • If false is returned within a filter, the value is filtered out.

I hope this clarifies.