Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to calculate the product of the elements in a Javascript array?

I was looking for a good explanation of calculating product of the elements in one array, but the answers I found are not working in my case.
I’m trying to find the product of two arrays and compare them.
Found some articles where is written that I can use this function:

    let total = 1; 
    for(let i = 0; i <= array.lenght; i++){
        if(isNaN(array[i])){
            continue;
        }else{
            total *= Number(array[i]);
        }
    }
    return total;
}

No matter what are the values in the array I’m always getting 1 as total. I’m posting the code, so if someone can show me my mistake or tell me some other way to calculate the product, I’ll be very grateful.

Here’s the code link

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

First your … i <= array.lenght; i++ …
your length misspelled into lenght

Please correct that

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading