How does javascript find all prime factors of a number?

encounters a javascript algorithm problem, which requires that find out all prime factors of a number

algorithm I designed:

function primeFactors(n){
    var factors = [];
    var divisor = 3;
    if (n % 2==0) factors.push(2);
    while(n>5){
        if(n % divisor == 0){
            !factors.includes(divisor) && factors.push(divisor);
            n= n/ divisor;
        }
        else{
            divisor+=2;
        }
    }
    return factors;
};
console.log(primeFactors(666));

the running result is
clipboard.png

although the operation results seem to be correct, I feel that the design of the algorithm is too low and the performance is low. I would like to ask for the help of God to analyze and write a better algorithm. Thank you.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf735b-32047.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf735b-32047.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?