Javascript - Error creating objects on the fly
<p>I am trying to simulate data to a function that would usually receive a JSON parsed data structure.  When running this I get an error <code>TypeError: can't convert undefined to object</code> here: <code>data.targets[i] = {</code></p>

<p>What am I doing wrong?</p>

<pre><code>function SendFakeTargets(maxTargets, interval) {
    var data = {};
    data.timestamp = +new Date;

    var time = data.timestamp * 0.0005;
    var x = Math.sin(time) * 192 + 256;
    var y = Math.cos(time * 0.9) * 192 + 256;

    console.log(x, y);

    for (var i = 0; i &lt; maxTargets; i++) {
        console.log(i);

        data.targets[i] = { //error is here
            id: i,
            x: x + (i * 10),
            y: y + (i * 10)
        };
    }

    HandleTargetData(data);

    setTimeout("SendFakeTargets("+maxTargets+", "+interval+")", interval);
}
</code></pre>
