Below code from URL (http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_state_forin) returns "John Doe 25". How can I fetch the property names like "fname lname age"?
<!DOCTYPE html>
<html>
<body>
<p>Click the button to loop through the properties of an object.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var person = {fname:"John", lname:"Doe", age:25};
var text = "";
var x;
for (x in person) {
text += person[name] + " ";
}
document.getElementById("demo").innerHTML = text;
}
</script>
</body>
</html>
nameisn't defined in your code. Did you meanperson[x]?