I have 2 arrays like so:
var arrayOne = [
{page:'1',tags:['foo','bar']},
{page:'2',tags:['oh','boy']}
];
var arrayTwo = [
{page:'1',tags:['go','out']},
{page:'9b',tags:['red','blue','green']}
];
I want to compare the two arrays, and if the page property is the same, replace the tags property in arrayOne with the tags property from arrayTwo.
So given the example arrays above, only the tags for page: 1 of arrayOne would get replaced with page: 1‘s values from arrayTwo.
I’m thinking I can do this with underscore.js, but I’m struggling to see how.
Ideas?
I was able to do what I needed by using Underscore’s
_eachby doing one inside of another like so ( http://jsfiddle.net/4JP7g/ ) :