Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

make array from "difference" between two arrays

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

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

730 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