I'm having afunction that is merging two arrays like this:
var sorting = data.genre.map((i) => data_info.find((o) => o.id === i));
The problem in this function is if it couldn't find genre
in data_info
it adds null
to the object arra and therefore my function fails.
So the question is: How could I remove in above single line all values that are null?
I get this output from thr line above:
[{"id":1,"category":"Action"},{"id":2,"category":"Adventure"},null]
And need to get this:
[{"id":1,"category":"Action"},{"id":2,"category":"Adventure"}]
I tried to add && data_info(o) !== null
to the line above but I get null
in the object array anyway.