I have the following code:
let id = '';
let text = '';
// Note: `match` = [full match, id (first group), text (second group)]
if (match.length > 1) {
[, id] = match;
}
if (match.length > 2) {
[, id, text] = match;
}
return { id, text };
match
could be null, or lengths between 1-3.
id
and text
need to be empty strings by default and only set if match
is not null and of certain length.
How can I shorten this up?
Possibly avoiding the if statements.