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 7697705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:04:33+00:00 2026-05-31T22:04:33+00:00

A few days ago I posted a thread asking on how to find the

  • 0

A few days ago I posted a thread asking on how to find the missing element when passing a method 2 JS arrays. As you can see here. I’ve been trying to figure out now how to modify the method so that instead of passing it 2 Arrays you pass it 2 2D-Arrays… Having some trouble though:

/*var sml = new Array();
sml[0] = new Array("dean","22");
sml[1] = new Array("james","31");
sml[2] = new Array("ludwig","35");

var lrg = new Array();
lrg[0] = new Array("dean","22");
lrg[1] = new Array("james","31");
lrg[2] = new Array("ludwig","35");
lrg[3] = new Array("kevin","23");
lrg[4] = new Array("elton","40");*/

var sml = new Array();
sml[0] = "dean";
sml[1] = "james";
sml[2] = "ludwig";

var lrg = new Array();
lrg[0] = "dean";
lrg[1] = "james";
lrg[2] = "ludwig";
lrg[3] = "kevin";
lrg[4] = "elton";


var deselected = findDeselectedItem(sml, lrg);

alert("Deselected Items: " + deselected[0]+", "+ deselected[1]);

// -------------------------------------------------------------- //

function findDeselectedItem(CurrentArray, PreviousArray) {


var CurrentArrSize = CurrentArray.length;
var PreviousArrSize = PreviousArray.length;
var deselectedItems = new Array();

// loop through previous array
for (var j = 0; j < PreviousArrSize; j++) {

    // look for same thing in new array
    if (CurrentArray.indexOf(PreviousArray[j]) == -1)

    deselectedItems.push(PreviousArray[j]);

}

if (deselectedItems.length != 0) {
    return deselectedItems;
} else {
    return null;
}

}​

Now if you run the above code it works perfectly, but if you go and uncomment the variable declarations on top that that pushes arrays ontop of the array, and then comment out the simple strings that get pushed on top of the array, it doesn’t work as well… For instance:

var sml = new Array();
sml[0] = new Array("dean","22");
sml[1] = new Array("james","31");
sml[2] = new Array("ludwig","35");

var lrg = new Array();
lrg[0] = new Array("dean","22");
lrg[1] = new Array("james","31");
lrg[2] = new Array("ludwig","35");
lrg[3] = new Array("kevin","23");
lrg[4] = new Array("elton","40");

/*var sml = new Array();
sml[0] = "dean";
sml[1] = "james";
sml[2] = "ludwig";

var lrg = new Array();
lrg[0] = "dean";
lrg[1] = "james";
lrg[2] = "ludwig";
lrg[3] = "kevin";
lrg[4] = "elton";*/


var deselected = findDeselectedItem(sml, lrg);

alert("Deselected Items: " + deselected[0]+", "+ deselected[1]);

// -------------------------------------------------------------- //

function findDeselectedItem(CurrentArray, PreviousArray) {


var CurrentArrSize = CurrentArray.length;
var PreviousArrSize = PreviousArray.length;
var deselectedItems = new Array();

// loop through previous array
for (var j = 0; j < PreviousArrSize; j++) {

    // look for same thing in new array
    if (CurrentArray.indexOf(PreviousArray[j][0]) == -1)

    deselectedItems.push(PreviousArray[j][0]);

}

if (deselectedItems.length != 0) {
    return deselectedItems;
} else {
    return null;
}

}​

The method returns 2 completely wrong values. PS – I’m not interested in the “numbers” just yet, just the “names” for now…

  • 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-05-31T22:04:34+00:00Added an answer on May 31, 2026 at 10:04 pm

    You could also rearrange the array like this:

    var sml = {};
    sml["dean"] = 22;
    sml["james"] = 31;
    sml["ludwig"] = 35;
    
    var lrg = {};
    lrg["dean"] = 22;
    lrg["james"] = 31;
    lrg["ludwig"] = 35;
    lrg["kevin"] = 23;
    lrg["elton"] = 40;
    

    and use:

    function findDeselectedItem(c,p){
        ret=[];
        for (var i in p){
            if (p.hasOwnProperty(i)){
                if ('undefined'===typeof c[i]) {
                    ret.push(i);
                }
            }
        }
        return ret;
    }
    
    
    alert(findDeselectedItem(sml, lrg));
    

    Demo: http://jsfiddle.net/LsrCj/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I posted a thread on here a few days ago relating to this file,
I've posted the same question here a few days ago( Java reading standard output
A few days ago, I posted this question and this question asking about how
A few days ago I posted this question and everyone suggested me to use
I posted somethign relating to this a few days ago...but I still havent't resolved
This is a spin off from another question I posted a few days ago
few days ago I asked here about implementing USB. Now, If I may, would
A few days ago I asked about passing a data structure from java to
I posted a few posts there a few days ago, but my posts were
I posted this question a few days ago, and I have some follow up

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.