Home (Javascript) How to find unique values from an array and put them into another using booleans?
Reply: 0

(Javascript) How to find unique values from an array and put them into another using booleans?

user887
1#
user887 Published in June 20, 2018, 10:41 pm

So let's say I have my first array (arrayOne) with the values of [1,2,3,3,4,2]. I need to compare this array to another array to check for duplicate values (arrayTwo), then display these values.

So, the final output would be: 1, 2, 3, 4.

The catch is I can only use really basic methods, pretty much just booleans, multiple functions, and loops.

How might I go about this? Searching the internet brings up code similar to this:

for (a = 0; a < array1.length; a += 1) {
    for (b = 0; b < array2.length; b += 1) {
        if (array1[a] !== array2[b])
            array2 = array1
        }
    }
}

output = array2   

... so on so forth, but this doesn't seem to work for me (note my code is not exactly like this, but after searching, this seems to be close to what I am looking for).

Any advice?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311568 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO