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 can I multiply an array elements between another array?

I want to do it with the forEach loop but I can’t do it, what I want to do is the following

For example i have the first array:

let numbersA = [4,5,6,7,8];

Then i have the last array:

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

let numbersB = [2,3,4,5,6];

The expected output:

4 * 2 = 8

4*3 = 12

4 * 4 = 16

4 * 5 = 20

4 * 6 = 24

and now comes the second multiplication of the first array of the second number:

5 * 2 = 10

5 * 3 = 15

5 * 4 = 20

5 * 5 = 25

5 * 6 = 30

How can I get this result, I want to do it with the forEach loop, using arrow functions but I got stuck

>Solution :

You could use Template Literals to print out the equation:

let numbersA = [4, 5, 6, 7, 8];
let numbersB = [2, 3, 4, 5, 6];
numbersA.forEach(a => {
    numbersB.forEach(b => console.log(`${a} * ${b} = ${a * b}`));
});
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