After using push()
method, I print the item arr[i].title
into console and it shows 'undefined', instead of "God father 1". See line 12 of the code.
Here is the code:
<!doctype html>
<html lang="en">
<head>
<title> Document Object Properties </title>
<meta charset="utf-8">
<script>
window.onload = init;
function init() {
var arr = [];
for (var i=0; i < 3; i++) {
arr.push(new Movie("God father " + i,1970,"Cowboy",15,["13:00","17:00","21:00"]));
console.log("Array item: " + arr[i].title); // WHY Undefined???
for (var j=0; j < 3; j++) {
//arr[i].showtimes[j] = "0" + i + ":00";
}
}
var div = document.getElementById("result");
div.innerHTML =
"Movie: " + arr[0].title + "<br>" +
"Year: " + arr[0].year + "<br>" +
"Genre: " + arr[0].genre;
}
function Movie(title,year,genre,rating,showtimes) {
var title= " ";
var year= 2000;
var genre= " ";
var rating= 15;
var showtimes= [];
}
</script>
</head>
<body>
<div id="result">
</div>
</body>
</html>