JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects Accessing All of the Properties in an Object

William Ray Noble
William Ray Noble
11,748 Points

for ( prop in shanghai ) { console.log(prop); } What am I missing? TIA.

This method worked on the previous video assignment, what am I missing? Thank you in advance.

script.js
var shanghai = {
  population: 14.35e6,
  longitude: '31.2000 N',
  latitude: '121.5000 E',
  country: 'CHN'
};

for ( prop in shanghai ) {
  console.log(prop);
}
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

1 Answer

Steven Parker
Steven Parker
195,561 Points

You forgot to declare the loop variable:

for (var prop in shanghai) {
//   ^^^