Solved

make array from "difference" between two arrays

Posted on 2012-03-22
2
242 Views
Last Modified: 2012-03-22
I have two arrays. One has many number. One has only ten. All the numbers that exist in the smaller array also exist in the smaller array. I'm trying to make an array of the numbers that do not exist in the smaller array.

var unusedArr = [];
for (x in idsToFade) {

    for (y in cleanIdArray) {

        if (idsToFade[x] != cleanIdArray[y]) {
            unusedArr.push(cleanIdArray[y]);
        }

    }

}
console.log(unusedArr);¿

Open in new window

My problem is that unusedArr gets filled with the values 10 times, because that is the length of the array i'm basing the first for in loop on (idsToFade).

I feel I am missing something pretty basic. Much appreciative for any help!
0
Comment
Question by:hibbsusan
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 37755130
0
 

Author Closing Comment

by:hibbsusan
ID: 37755167
i looked for so long for something exactly like that. Thank you!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now