Skip to content
Advertisement

Tag: flatmap

Return no element from `Array.flatMap()` by if condition

I have this code: The above code used a ternary operator of condition ? exprIfTrue : exprIfFalse. Currently I’m returning empty objects of { } in the case of exprIfFalse. How can I return nothing in the case of exprIfFalse? I mean, I want absolutely nothing. I mean no array element. Answer Why cant you just return an empty array,

Flatten nested JavaScript object

I have a nested object and I want to flatten/map it into a single-layered, table-like object. From that, I want to get something like this: Sure, I could simply iterate over the object with two for loops and put the result info a separate array, but I wonder, if there is a simpler solution. I already tried to play around

Advertisement