js 学习之路8:for循环
程序员文章站
2022-07-03 17:50:07
1. for循环 结果: 2. for/in循环直接遍历循环对象的属性。 结果: ......
1. for循环
<!doctype html> <html> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <body> <script charset = "utf-8"> namelist = ["kl", "td", "mgeno", "bobo"]; for (var i = 0; i < namelist.length; i++) { document.write(namelist[i] + "<br>"); } </script> </body> </html>
结果:
2. for/in循环直接遍历循环对象的属性。
<!doctype html> <html> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <body> <script charset = "utf-8"> var maninfo = {name: "tim", age: 20, grade: 98}; for (var i in maninfo) { var info = i + ": " + maninfo[i]; document.write(info + "<br>"); } </script> </body> </html>
结果: