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?
Thanks!
var movies = [...watchList];
var filteredList = watchList.map(function(movies) {
//var ratings = parseInt(movies.imdbRating);
if (movies.imdbRating > 8) {
return ("\"title\": " + movies.Title + " ," + "\"rating\": \"" + movies.imdbRating + '\"\ ');
}
else {
return false;
}
});