Creating a json array and json items with jquery?
<p>I made a simple javascript class like this:</p>

<pre><code>function Horse() {
    this.color = 'brown';
    this.speed = 'somewhat slow';
}
</code></pre>

<p>I attached a few instances to some elements, like this:</p>

<pre><code>$("#horse1").data('d', new Horse());
$("#horse2").data('d', new Horse());
$("#horse3").data('d', new Horse());
</code></pre>

<p>now I want to create a JSON array with a JSON representation of each horse object. So I'm doing this:</p>

<pre><code>// How do I create an empty JSON array here?:
var myJsonArray = ?;

var children = $("#horses").children();
for (var i = 0, m = children.size(); i &lt; m; i++) {
    var panel = children[i];
    var horse = $(panel).data('h');

    // And how do I create a JSON rep of my horse here?
    var myJsonHorse = new JsonHorse(?);

    // Finally, how do I add it to the json array?
    myJsonArray.push(myJsonHorse);
}
</code></pre>

<p>yeah my end goal is to have a single json array of all the horses after iterating over all the children - not sure if this should be done in plain javascript or in jquery?</p>

<p>Thanks</p>

<p>---------------- Edit -------------------</p>

<p>Sorry, my end goal is to then convert the array to a string, so I have one large json array converted to a string that I can submit to an ajax call that will get processed by my server.</p>
