If you actually have two arrays of JavaScript objects like this:
var a1 = [
{page: '1', tags: ['foo', 'bar']},
{page: '2', tags: ['oh', 'boy']},
//...
];
var a2 = [
{page: '1', tags: ['go', 'out']},
{page: '9b', tags: ['red', 'blue', 'green']},
//...
];
Then I'd convert a2 to a page-to-tags lookup table:
var lookup = { }, i, e;
for(i = 0, e = a2[i]; i < a2.length; e = a2[++i])
lookup[e.page] = e.tags;
and then spin through a1 merging in lookup values as you go:
for(i = 0, e = a1[i]; i < a1.length; e = a1[++i])
e.tags = lookup[e.page] || e.tags;
Demo: http://jsfiddle.net/ambiguous/aDgH7/
If you must use Underscore, you could replace the loops with _.reduce and _.each:
var lookup = _(a2).reduce(function(lookup, e) {
lookup[e.page] = e.tags;
return lookup;
}, { });
_(a1).each(function(e) {
e.tags = lookup[e.page] || e.tags;
});
Demo: http://jsfiddle.net/ambiguous/rkMZz/
If you could assume a modernish JavaScript, then the standard reduce and forEach array methods could be used:
var lookup = a2.reduce(function(lookup, e) {
lookup[e.page] = e.tags;
return lookup;
}, { });
a1.forEach(function(e) {
e.tags = lookup[e.page] || e.tags;
});
Demo: http://jsfiddle.net/ambiguous/cy2Qy/
If you actually have arrays of JSON strings then you can mix in JSON.parse and JSON.stringify calls to unpack and repack the data.
'from the final entry inarrayTwo? Is that a typo here, or in your real code?