Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

make array from "difference" between two arrays

Posted on 2012-03-22
2
Medium Priority
?
269 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 83

Accepted Solution

by:
leakim971 earned 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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)
Suggested Courses

885 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