js中的for...in循环

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

</head>
<body>
	
<p>点击下面的按钮,循环遍历对象 "person" 的属性。</p>
<button onclick="myFunction()">点击这里</button>
<p id="demo"></p>
<script>
function myFunction(){
	
	var person={fname:"哈哈",lname:"尔尔",age:12}; 
       var x;
	var txt="";
for (x in person){txt=txt + person[x]+" ";}document.getElementById("demo").innerHTML=txt;}</script></body></html>

猜你喜欢

转载自blog.csdn.net/qq_26925297/article/details/80319214