Randomly select enumerable property of object in Javascript
<p>Given a dictionary-like object in Javascript such as <code>{a:1, b:-2, c:42}</code>, is there a simple way to randomly choose a property? </p>

<p>In the above example, I would like to have a function that would return <code>a</code>, <code>b</code> or <code>c</code> randomly.</p>

<p>The solution I've come up with is like the following:</p>

<pre><code>    var proplist = []
    forEach(property in foo) {
        if(propertyIsEnumerable(foo[property]) {
            proplist.push(property);
        }
    }
    var n = proplist.length;
    // randomly choose property (randInt(n) returns a random integer in [0,n))
    proplist[randInt(n)];
</code></pre>

<p>Is there a more idiomatic way to do this?</p>
