The for...in statement is used to loop (iterate) through the elements of an array or through the properties of an object.
循环对象的所有属性:
<script> var o = {a:'aa', b:'bb', c:'cc'}; for(var p in o) { alert(eval("o." + p)); } </script>
循环数组的所有元素:
<script> var arr = ['11', '22', '33']; for(var i in arr) { alert(arr[i]); } </script>
博客园 © 2004-2025 浙公网安备 33010602011771号 浙ICP备2021040463号-3