<body>
<script src=""></script>
<script type="text/javascript">
let news = [‘asia new’,’europe news’,’america news’];
for (let index = 0; index < news.length; index++) {
alert(news[index]);
}
</script>
</body>
#### 2) forEach in javascript
<body>
<h2><?echo=’News’?></h2>
<ol>
<li><a href=""<?echo 'asia news'?></a></li>
<li><a href=""<?echo 'europe news'?></a></li>
<li><a href=""<?echo 'america news'?></a></li>
</ol>
<script src=""></script>
<script type="text/javascript">
let news = [‘asia news’,’europe news’,’america news’];
news.forEach(news=>console.log(news));
</script>
</body>
<?php
$news = [‘asia news’,’europe news’,’america news’];
for ($i=0; $i < count($news) ; $i++) {
echo $news[$i]. ‘<br>‘;
}
?>
<?php
$news = [‘asia news’,’europe news’,’america news’];
foreach($news as $news)
{
echo $news.’<br>‘;
}
?>
效果跟上面是一样的