for (语句 1; 语句 2; 语句 3) {
要执行的代码块4
}
//先1 然后2为true 执行4 然后3 然后243循环 ,直到2为false
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"></head>
<body>
<h1>JavaScript 循环</h1>
<p id="demo"></p>
<script>
var cars = ["BMW", "Volvo", "porsche", "Ford", "Fiat", "Audi"];
var text = "";
var i;
for (i = 0; i < cars.length; i++) {
text += cars[i] ;
console.log(text)
//打印日志,右击页面检查 选择console
}
alert(cars)
document.getElementById("demo").innerHTML = text;
</script>
</body>