Parsing numbers and ranges from a string in Javascript
On modern environments that support it (which is pretty much all of them except Safari), you can make it a bit nicer by using matchAll instead of match, and use capture groups to capture the digits immediately, rather than having to use an .includes check and split afterwards:



function parse(string) {
    const numbers = [];
    for (const [, beginStr, endStr] of string.matchAll(/(\d+)(?:-(\d+))?/g)) {
        const [begin, end] = [beginStr, endStr].map(Number);
        numbers.push(begin);
        if (endStr !== undefined) {
            for (let num = begin + 1; num &lt;= end; num++) {
              numbers.push(num);
          }
        }
    }
    return numbers;
}

console.log(parse('11 14-16 18-20'));




(For older environments, you'll need a polyfill)

Also note that you should always use const to declare variables whenever possible - only use let when you need to warn readers of the code that you may have to reassign the variable in the future.