bagaimana menemukan faktor angka dalam javascript

// how to find factors of a number in javascript
function factors(n){
  let arr = [];
  for(let i =1; i<=n; i++){
    if(n % i === 0){
      arr.push(i);
    }
  }
  return arr;
}
console.log(factors(147)); // [ 1, 3, 7, 21, 49, 147 ]
Chetan Nada