Merge loops with jQuery.extend: last value is always the same?
<p>I have two arrays of "hashes". I need to merge them together so the end result is another array of hashes, except the number of entries is the product of the two arrays.</p>

<pre><code>    inhabitants = {}
    idx = 0
    for (i=0; i&lt;persons.length; i++) {
        person = persons[i];
        for (j=0; j&lt;houses.length; j++) {
            house = houses[j];
            console.log(house);
            inhabitants[idx] = $.extend(person,house);
            console.log(inhabitants[idx]);
            idx++;
        }
    }
</code></pre>

<p>What I end up with is a silly number of entries that depends on the ordering of the parameters in the $.extend() line. And the "house" entry that is added is ALWAYS THE LAST ENTRY IN THE ARRAY.</p>

<p>Clearly this $.extend() from jQuery is not doing what I expect. Can anyone help?</p>
