4
Hello! I’m having trouble understanding how I can filter the answer I get from my database, its logic is like this:
I receive an array of objects from which it has the values of use, useridRequerent and useridRetailed, the first value is only to know what situation is that bond of friendship, what matters in this situation is what occurs between the two values.
The user who sends a friend request to another user becomes the Claimant and the user who accepts this friend request is the Defendant. In this case above, the user who is logged in to my system has his id = 6, therefore he is the Plaintiff of the first two relations and the Respondent of the third relation since his number can be found in these three values shown above.
So my goal is to filter the ids unlike the one my user id belongs to, ie if it is id equal to 6, for the indices of 0 and 1, I want to rescue only the useridRedear of which are 2 and 4, but at the same time I want to redeem the value of useridRequerent, since in the third part of this array, id 6 user is the useridRequeried, so it would come along the value of 1.
The first coherent attempt on my head that I made was to condition in a loop of .filter() with an id include on one of the two values in this way:
But the result is always incomplete:
The same is true when I step one && in the condition with useridRequeried, I have used other ties as .map() or .Every() with almost equal conditions in this response array and I still haven’t got the result I’m really waiting for, which way should I do so I can filter through this logic above?
It’s just the second function I’ve seen that I really need, however it returns to me Undefined together with the values I need, there is how to return only the values without these undefineds?
– Rafael Soares
@Rafaelsoares The answer has been edited to support your question. Just a second iteration in the same function but in the array filtered, by inserting whatever has value (not
null
,undefined
etc.) in a second array that will return from the function.– Ruan Montelo