Get filter to return nothing when condition is false

I am working on the “Use the Filter Method to Extract Data from an Array” challenge.

I can get my code to return the correct info for the parts of the array that meet the condition, but for the ones that evaluate to false, it returns undefined. I want it to return nothing at all. If the last element of the input array does not meet the condition, then I want it to be excluded from the new array.

I cannot think of how to do that. Does anyone have a hint for me?


var movies = [...watchList];

var filteredList = {
//var ratings = parseInt(movies.imdbRating);
 if (movies.imdbRating > 8) {

return ("\"title\": " + movies.Title + " ," + "\"rating\": \"" + movies.imdbRating + '\"\ ');

 else {
   return false;

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


You’re not filtering, you’re using map, which takes an array, transforms every element in the array, then returns that new array. It can’t decrease or increase the size of the array.

Thank you. That’s really obvious in hindsight. It’s great to get another pair of eyes on a problem sometimes, I guess.