for/in

The for in loop iterates through an objects properties: 

<html>
	<head>
		<title>JavaScript</title>
	</head>
	<body>
	<script type="text/javascript">
		var val;
		var bike = {Make:"Ducati",Model:"Panigale",CC:1198};

		for (val in bike) {
			document.write(bike[val] + "<br>");
		}
	</script>
	</body>
</html>

Save & refresh browser:

Ducati
Panigale
1198

Leave a Reply