website works fine, but in terminal i have this warning Array.prototype.map() expects a value to be returned at the end of arrow function
. How do i fix this?
i tried using forEach, there is no warning but the section doesn’t show what I wrote.
website works fine, but in terminal i have this warning Array.prototype.map() expects a value to be returned at the end of arrow function
. How do i fix this?
i tried using forEach, there is no warning but the section doesn’t show what I wrote.
2
Answers
You have to listen to the error. It’s because you’re not returning anything if the value’s category is not "education". You must have a return value for every element in the array for
map
to work. As @Andy pointed out in the comments, you have tofilter
the array for the category you want, and thenmap
the items to the values you want.As Andy said, to make sure everything runs smoothly, I recommend using a
.filter
function first, then the.map
function. To give you a better idea, here’s an example:If no Data meet the filter criteria, the function will return an empty array. This array will then be passed to
.map
, resulting in no actions being taken. Put simply, if there are no matches, there is nothing to display.