Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8724733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:53:28+00:00 2026-06-13T07:53:28+00:00

I have 2 arrays like so: var arrayOne = [ {page:’1′,tags:[‘foo’,’bar’]}, {page:’2′,tags:[‘oh’,’boy’]} ]; var

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:53:29+00:00Added an answer on June 13, 2026 at 7:53 am

    I was able to do what I needed by using Underscore’s _each by doing one inside of another like so ( http://jsfiddle.net/4JP7g/ ) :

    var arrayOne = [
        {page:1,tags:["foo","bar"]},
        {page:2,tags:["oh","boy"]}
    ];
    var arrayTwo = [
        {page:1,tags:["go","out"]},
        {page:9,tags:["red","blue","green"]}
    ];
    
    _.each(arrayOne, function(one){
        _.each(arrayTwo, function(two){
          if(one.page === two.page){
                    one.tags = two.tags;  
                    console.log (one.tags);            
          }           
        });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three arrays: var arrayOne=[{obj1}, {obj2}, {ob3}]; var arrayTwo=[{obj4}, {obj5}, {obj6}]; var arrayThree=[{obj7},
I have two string arrays in javascript like var names = [name1, name2, name3,
Say I have a collection of object arrays of equal dimension, like this: var
I have two different arrays like this var images = [{ src: images2/animal_1.jpg, title:
I have 3 arrays like: var arr1 = []; var arr2 = []; var
I have two arrays, the main includes something like 300 values: var main =
I have two arrays. One looks like this: var array_one = [.a, .b, .c,
I have two json arrays like var json1 = [{id:1, name: 'xxx' ...}] var
I have an array with nested arrays that looks like this: var tw =
I have an array like this var array = [{ order: 3, sub -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.