I want to display all the properties of the object Wine1 along with their respective values .But this code is not working:
<html>
<head>
</head>
<body>
<input type="button" value="Button" onClick="f1()">
<script type="text/javascript">
function f1()
{
var Wine1=new Object();
Wine1.color="Red";
Wine1.price="50000 USD";
Wine1.vine-yard="South";
var record="Wine1<br><br>";
for(var prop in Wine1)
{
record+=prop+"="+Wine1[prop]+"<BR>";
}
record+="<br>";
document.write(record);
}
</script>
</body>
</html>
Someone please help me to find the mistake.
Wine1.vine-yardwithWine1['vine-yard']and it should work fine.Wine1.vineYardwould be a better replacement.Wine1.vineyard:P but this change and your change could have impact on other places in his code.record="test";overwrites the string you carefully built! Did you mean `record += "test"?