title: How do I create a function that extracts the middle to end of strings of different lengths?
body: <p>I am trying to make a function that adds a space between &quot;flight&quot; and &quot;###&quot; but would like to make it work if the flight number is greater than 3 digits. I know I could make the second part of the slice method a huge number and it would technically work but I figure there should be a more elegant way. Any help would be appreciated, thanks!</p>
  <pre><code>const addSpace = function (str) {
        const flightNumber = str.slice(6, 9);
        return [str.slice(0, 6) + ' ' + flightNumber]
      }
      
      console.log(...addSpace('flight843'));
  </code></pre>