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

Get all result not just the last one

Hope you all are doing well. I have problem with for loop i want to get all result not just the last one.

for (var i = 1; i < 5; i++) {
     var result = "";
     result += i;
}
console.log(result)

Can you please help me to resolve it. Thanks <3

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 :

try using let and move the result ="" outside loop

let result="";

for (let i = 1; i < 5; i++) {
     result += i;
}
console.log(result)
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