Core JavaScript

Using a For-In Loop to List Properties

This JavaScript example uses a for-in loop to list the properties of an object.

ForInLoopOnObjectProperties.html

<!DOCTYPE html>
<html>
<head>
    <title>XoaX.net's Javascript</title>
</head>
<body>
    <script type="text/javascript" src="ForInLoopOnObjectProperties.js"></script>
</body>
</html>

ForInLoopOnObjectProperties.js

var qMysteries = { sFirst:"The Resurrection", sSecond:"The Ascension",
  sThird:"The Descent of the Holy Spirit", sFourth:"The Assumption",
  sFifth:"The Coronation of Mary"};

for (sProp in qMysteries) {
	document.writeln(sProp + " : " + qMysteries[sProp] + "<br />");
}
 

Output

 
 

© 2007–2024 XoaX.net LLC. All rights reserved.