Conditionally Include Pairs In An Object
You can add key-value pairs to an object using the ES6 spread operator:
By combining the spread operator with some boolean logic, you can conditionally add key-value pairs to an object:
Depending on the value of isArriving
:
or
This is useful for dynamically building up some configuration object or data payload.
Last updated