Check out example codes for "Use Recursion to Create a Range of Numbers". It will help you in understanding the concepts better.

Code Example 1

function rangeOfNumbers(startNum, endNum) {
  if (endNum - startNum === 0) {
    return [startNum];
  } else {
    var numbers = rangeOfNumbers(startNum, endNum - 1);
    numbers.push(endNum);
    return numbers;
  }
}

Learn ReactJs, React Native from akashmittal.com