Solved

make array from "difference" between two arrays

Posted on 2012-03-22
2
252 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find out all repos that a user is most active on Github 1 26
javascript form submition 2 20
Html date format 9 20
Html using "Or" in condition 3 24
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

680 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