Json length is always undefined in node js
<p>I am trying to iterate simple json array, but it always return the length of the array is <strong>undefined</strong>.</p>

<pre><code>var chatmessage = {};
...................
...................
socket.on('listmessage', function(mesg){ 
chatmessage={"message":"Hello", "to":"sjdfjhsdf"};
});

socket.on('private', function(mesg){ 
console.log(chatmessage.length+' - '+chatmessage.message +' - '+ chatmessage.to);
}); 
</code></pre>

<p>when private event get trigger it returns</p>

<pre><code>undefined - Hello - sjdfjhsdf
</code></pre>

<p>I think it consider <strong>length</strong> key word as a json array key like <strong>{"length":40}</strong>.</p>

<p>I have tried <strong>Object.keys(chatmessage).length</strong> but it returns the total number key value(<strong>2</strong>) but I have only one record.</p>

<p>What is the right way to iterate json in node js</p>