Working with Objects & Arrays using .Map() and maybe .filter() method

Hello,
I’ve written the following code:
https://codepen.io/matforc/pen/LdEyoL?editors=1011

it doesn’t work as expected and I can clearly see that is not clean at all, especially starting from line 45, how I can write it in a better “functional” way, do I have to use filter method?.
Thanks in advance
Regards
Matteo

Well for starters: && .
For seconds: Map expects every callback to return something. If you’re wanting to get a filtered array back, then indeed the .filter() method is what you want. Note that filter’s callback expects a boolean response.

yes, the target get in the postsCats variable an array of the objects that have in the category property array the two numbers stared in the var relatProdId and the var prodId. How would you implement this?
Thanks in advacne

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.