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***);
});