Best way to handle concatenating string with another function
<p>I am working on cleaning up some adopted code - there is a lot of duplication.</p>

<p>There is a set of jQuery callbacks where we get back JSON like this:  </p>

<pre><code>[
{"location":{"id":164,"name":"place 1"},"users":[{"id":1,"name":"joe"},{"id":2,"name":"jack"}]},
{"location":{"id":162,"name":"place 2"},"users":[{"id":3,"name":"joe"},{"id":4,"name":"jon"}]}
]
</code></pre>

<p>I go through with these functions:</p>

<pre><code>function locations_view(r) {
    str = "";

    $.each(r.data, function(k, v) {
        str += v.location.name + "&lt;br /&gt;";
        iterate_users(v.users);
    });

    $("#locations").html(str);
} 

function iterate_users(users) {
    str += '&lt;strong&gt;users:&lt;/strong&gt;' + users.length + '&lt;br /&gt;';

    $.each(users, function(k1, v1) {
        str += "&lt;a href='/users/" + v1.id + "'&gt;" + v1.name + "&lt;/a&gt; ";   
    });

    str += "&lt;br /&gt;";
}
</code></pre>

<p>This seems to work but it looks a little ugly. Is there a better way to do this. Also, I want to minimize memory consumption (returning the string rather than have a global <code>str</code> was causing performance issues). Is there a better, more elegant way to do this? Would having multiple copies of <code>str</code> ever cause a problem? Like if I have products_view that also uses a <code>str</code>?</p>
