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

  • SEARCH
  • Home
  • 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 7811631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:14:14+00:00 2026-06-02T04:14:14+00:00

I have this code: $(‘#find’).click(function(){ if(first.val() != ” && second.val() != ”){ $.getJSON(urlPersonSearch +

  • 0

I have this code:

$('#find').click(function(){
    if(first.val() != '' && second.val() != ''){
        $.getJSON(urlPersonSearch + first.val() + "?callback=?", function(json) {
            firstId = (json[0].id != undefined) ? json[0].id : '';
            if(firstId != '') result = grabMovies(firstId);
            var i = result[0].filmography.length;
            while(i--){
                movies[result[0].filmography[i].id] = result[0].filmography[i].name;
            }
        });
        $.getJSON(urlPersonSearch + second.val() + "?callback=?", function(json) {
            secondId = (json[0].id != undefined) ? json[0].id : '';
            if(secondId != '') result = grabMovies(secondId);
            var i = result[0].filmography.length;
            while(i--){
                movies[result[0].filmography[i].id] = result[0].filmography[i].name;
            }
        });

    }

});


function grabMovies(id){
    $.getJSON(urlPersonResult + id + "?callback=?", function(json) {
        return json;
    });
}

Now, what I’m trying to do, is end up with an object with ID and Movie Name as the key/value. Ultimately i’m trying to get an object which contains only the matches between the two json results. Ie.

if the first had a result of

23 = hello,
283 = goodbye,

and the second had a result of

23 = hello,
294 = bye

I would end up with an object of

23 = hello

Has anyone got any advice on how to do this?

  • 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-02T04:14:16+00:00Added an answer on June 2, 2026 at 4:14 am

    You’re looking for an array intersection function. Underscore.js has one. So I was all ready to tell you to use that, but it won’t do for this purpose. Look what I tried:

    var a = [{23:'hello'},{283:'goodbye'}],
        b = [{23:'hello'},{294:'bye'}];
    
    _.intersection(a,b); // produces []
    
    // investigating further
    a.indexOf({23:'hello'}); // -1
    

    The underlying problem here is object equivalency in JavaScript. Note also that

    ({23:'hello'} === {23:'hello'}); // false
    ({} === {}) // false
    

    Two JavaScript objects are not equivalent to each other, even if they have the same keys and values. This has to do with the object literal in Javascript calling a constructor under the hood, and thereby reserving a new loctation in memory.

    The solution

    Underscore appears to have a bug in its _.indexOf method. Other than that, it’s a fantastic library and I suggest you use it. I would just extend it with the following:

    _.mixin({
        deepIndexOf: function (array, item, isSorted) {
            if (array == null) return -1;
            var i, l;
            if (isSorted) {
              i = _.sortedIndex(array, item);
              return _.isEqual(array[i],item) ? i : -1;
            }
            for (i = 0, l = array.length; i < l; i++) if (i in array && _.isEqual(array[i],item)) return i;
            return -1;
        },
        deepIntersection: function (array) {
            var rest = Array.prototype.slice.call(arguments, 1);
            return _.filter(_.uniq(array), function(item) {
              return _.every(rest, function(other) {
                return _.deepIndexOf(other, item) >= 0;
              });
            });
          }
    });
    

    Now, you can run _.deepIntersection(a,b) like so:

    var a = [{23:'hello'},{283:'goodbye'}],
        b = [{23:'hello'},{294:'bye'}];
    
    _.deepIntersection(a,b); // produces [{23:'hello'}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: $('p', 'div.playlist').click(function(e){ if (e.target != this) { val = $(this).parent().attr('songid');
i have this code preg_match_all('%(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^&?/ ]{11})%i', $asd, $match); to find youtube key of urls
I have this code & I've tired using JQuery's appendTo() function to get this
I have this code: var one; $(#ma1).click(function() { var one = 1; }) $(body).click(function()
I have this code, but this line has some problem. var dataString = 'name='+name&'id='+id;
I have this code: <%= @r2_blog_posts = Refinery::Blog::Post.recent(2) %> <%= link_to(@r2_blog_posts.first) do %> <%=
I have this code: function get_id_from_coords (x, y) { x = parseInt(x); y =
I have this code and I need an explanation on what it does: function
I have this code: <div id=star-rating> <script type=text/javascript> $(function(){ $('#star-rating form').submit(function(){ $('.test',this).html(''); $('input',this).each(function(){ if(this.checked)
I have this code to fetch profile pictures and messages: $(document).ready(function() { var url

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.