Suppose I want to process some property of x objects in a collection array . But a collection may contain objects without such a property or even undefined . for example
let array = [
{x: 1},
{x: 2},
{},
{x: 4},
undefined
]
The idea protects itself from such cases with a default parameter. Let it be 0 . I tried to solve it like
array.map(({x: x = 0}) => process(x))
But it does not work on undefined . Is there a way to solve this problem with default parameters and destructuring without writing the verification / set code inside the map function?
Thenks
source
share