Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Use forEach to Iterate through an Array in JavaScript</title> </head> <body> <script> // Sample array var cities = ["London", "Paris", "New York", "Amsterdam"]; // Loop over array cities.forEach(function(value){ document.write("<p>" + value + "</p>"); }); </script> </body> </html>