javascript testing object properties
<p>I have a global object MyFruits that can have multiple properties. At a minimum, it has two properties: Apples and Oranges. I need to find out if it has more properties than just these two.</p>

<p>For the moment, I stringify MyFruits, create a new object with just the Apples and Oranges properties and stringify it too and compare the length of both strings. Something like this:</p>

<pre><code>var JsonString1 = JSON.stringify(MyFruits);

var test2 = new Object();
test2.Apples= MyFruits.Apples;
test2.Oranges= MyFruits.Oranges;

var JsonString2= JSON.stringify(test2);

alert(JsonString1.length - JsonString2.length);
</code></pre>

<p>For now, it initially seems like it's working: if MyFruits contains more properties than just the two main ones, the difference of length will be different from 0.</p>

<p>There's the <code>Object.keys(obj).length</code> method that can count the number of properties of an object but it's new and not supported in all browsers so I'm not going to use it.</p>

<p>Is this the best way to do it? Let me know if there's a better way.</p>

<p>Thanks for your suggestions.</p>
