In the code snippet below, I am attempting to extract barNames
from an object named bar
:
const {[id]: {'name': fooName} = []} = foo || {};
const {'keywords': {[fooName]: barNames}} = bar || [];
- Please note that although
fooName
exists, it is not present as a property withinkeywords
My goal is to assign an empty array to barNames
if fooName
does not exist in bar.keywords
. I have tried using the OR operator without success. I am looking for alternative solutions that do not involve additional ternary operators like ?, :, &&
, etc.
Any tips or hints would be greatly appreciated.