Can’t pass variable to .getRange()

I’m trying to write a script that gets a range who’s size is based on a constant. My the code I’ve been trying is below

//Save range based on number of components
  var numComponents = 3;
  var compRange = SpreadsheetApp.getActiveSheet().getRange(15,3,numComponents,3);
  var compValues = compRange.getValues();
  var components = "";

  //Convert the components into paragraph form
  for (var row = 0; row <= numComponents ;row++){
    
      components = components + compValues[row][1] + " " + compValues[row][2] + " "+ compValues[row][0]+ "n";
  };

Whenever I run this code, I get an error saying

Error: Cannot read property 1 of undefined

When I replace numComponents with 3, the code works perfectly, however that will not always be the case. How can I make it work properly?

Answer

It’s very likely that the problem is this expression row <= numComponents

Replace

for (var row = 0; row <= numComponents ;row++){

by

for (var row = 0; row < numComponents ;row++){