What is the most common way to deal with something such as the following?
const names = 'Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand '
let re = /\s*(?:;|$)\s*/;
console.log(names.split(re));
// ["Harry Trump", "Fred Barney", "Helen Rigby", "Bill Abel", "Chris Hand", ""]
// ^^^^^
>Solution :
Just add filter after split, something like this:
const names = 'Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand '
let re = /\s*(?:;|$)\s*/;
console.log(names.split(re).filter(Boolean));
// ["Harry Trump", "Fred Barney", "Helen Rigby", "Bill Abel", "Chris Hand"]
Keep in mind that this will filter out any other negative values as well like null, undefined, false, 0 etc.