I have the following code to get barNames from an object bar:
const {[id]: {'name': fooName} = []} = foo || {};
const {'keywords': {[fooName]: barNames}} = bar || [];
- Note:
fooNameexists, but doesn't exist inkeywordsas a property
I want to make barNames an empty array if an object fooName does not exist in bar.keywords. I tried to to use the OR operator but it doesn't seem to work. I don't want to use any more ternary operators like ?, :, &&, etc.
Any hints would be nice.
const barNames = bar.keywords[fooName] || []bar || ...could be used only ifbarwere undefined. Btw, it's logical OR, not a pipe.