For In statement usage example in Javascript

  • 2020-06-12 08:29:23
  • OfStack

This article illustrates the use of For In statements in Javascript. Share to everybody for everybody reference. The details are as follows:


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>For In  statements </title>
<script type="text/javascript">
function Student(name, age) {
  this.name = name;
  this.age = age;
}
var stu = new Student(" In the maldives ", 20);
// Traverse object 
for (var s in stu) {
  alert(s + ":" + stu[s]);
}
// Through the array 
var myArr = [1, 3, 5, 7, 9];
for (var i in myArr) {
  alert(i + ":" + myArr[i]);
}
</script>
</head>
<body>
</body>
</html>

Hopefully, this article has been helpful in your javascript programming.


Related articles: