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

Can I use another loop inside forEach in Javascript? or is it best i use to separate loops?

I am tasked to write a function that returns the missing uniform pieces of Company A or Company B. The function should look thru the array to determine which Company is the one with the missing piece. Can I use another loop inside forEach in Javascript? or is it best i use to separate loops? Any hints are appreciated.

function findCompanyName(uniformSet, uniformPieces) {
  uniformPieces.forEach((element) => {
    const splitedArrayUniPcs = element.split("_");
  });

  //return "example";
}

findCompanyName(
  ["shirt", "pants"],
  ["companyA_shirt", "companyA_pants", "companyB_shirt"]
); //return companyB

>Solution :

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

Can I use another loop inside forEach in Javascript?

Yes! There is nothing wrong with nested loops in Javascript.

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