Solved

make array from "difference" between two arrays

Posted on 2012-03-22
2
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

630 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