How to find missing numbers in a sequence with JavaScript?

To find missing numbers in a sequence with JavaScript, we use a for loop.

For instance, we write

for (let i = 1; i < numArray.length; i++) {
  if (numArray[i] - numArray[i - 1] !== 1) {
    //...
  }
}

to loop through the sorted array numArray with a for loop.

In it, we check if the current number being looped through numArray[i] is 1 less than the previous number numArray[i - 1] by subtracting them and see if the difference is 1.

If it’s not, then the numbers in between the 2 numbers are missing.