如何使代码从数组中读取?

How do I make the code read from the array?

const array2 = [1,2,3,4,5,6,7,8,9,10]

function primeFactorsTo(num)
  {
  var store  = [], i, j, primes = [];
  for (i = 2; i <= num; ++i)
    {
    if (!store [i])
      {
      primes.push(i);
      for (j = i << 1; j <= num; j += i)
        {
        store[j] = true;
        }
      }
    }

您好,我希望程序遍历 array2 中的每个数字并将质数存储在 primes[] 中。我正在自学,实施起来有点吃力

function primeFactors(n) {
  const factors = [];
  let divisor = 2;

  while (n >= 2) {
    if (n % divisor == 0) {
      factors.push(divisor);
      n = n / divisor;
    } else {
      divisor++;
    }
  }
  return factors;
}
var arr = [1,2,3,4,5,6,7,8,9,10]
// Like this you can pass array to function
for(arrs of arr){
console.log(primeFactors(arrs))
}