Help with my "Smallest Common Multiple" code

Hi guys,

I’m stuck on this one. My code works with all ranges when the answer tends to be less than 150000 or so. Answers greater than that don’t work. The console gives me an error saying a possible infinite lop on line 15.

This is my code:

function smallestCommons(arr) {
var array=[];var array2=[]; 
  
arr.sort(function(a,b){
    return  b-a; 
});

  for (var i=arr[0];i>=arr[1];i--){
    array.push(i);
  }
 
  var total;
  
  for (var t=1;t<1000000;t++){
  for (var k=0;k<array.length;k++){
    if(t % array[k]==0){
      
      array2.push(t);
    }
  }
  
    if (array2.length<array.length) {
     array2=[];
   } 
  if (array2.length==array.length){
    return array2[0];
  }
    
  }
 
}

smallestCommons([1,12]);

Thanks! any feedback will be greatly appreciated. Greetings from Costa Rica!

Thanks for the heads up and editing my post. It’s definitely easier to read.

Any advice on why the code doesn’t work?