Saturday, November 14, 2015

Javascript Tutorial For Beginners 11 # JavaScript for Loop







<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>javascript</title>
</head>
<body >
<p id="demo"></p>
<p id="demo1"></p>

<script type="text/javascript">
var a;
var result="";
/* while (a <= 10) {
  result += "<br>" + a;
  a++;
 }*/

var names = ["tom", "mark","Ben","jack","john"];
for (a=0,result=""; a < names.length ; a++) {
 result += "<br>" + names[a];
}
document.getElementById("demo").innerHTML= result ;

var student = {name:"Mark", surname:"tesar", age:22};
var x;
var result1="";
for (x in student)
 result1 += "<br>" + student[x];
document.getElementById("demo1").innerHTML= result1 ;

</script>
</body>
</html>







No comments:

Post a Comment