Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #17150

Re: Unique values of array

Newsgroups comp.lang.javascript
Subject Re: Unique values of array
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <f874a1da-b06c-43af-beb6-fe05c5245469@p22g2000vby.googlegroups.com> <kU7v+sED7UnQFwmG@invalid.uk.co.demon.merlyn.invalid> <f3044be9-979c-448d-94c6-b85acd8ac102@r7g2000vbo.googlegroups.com> <XnsA107CEB5622C2eejj99@194.109.133.133>
Date 2012-11-10 20:26 +0100
Message-ID <XnsA107CFF43E30Eeejj99@194.109.133.133> (permalink)

Show all headers | View raw


Evertjan. wrote on 10 nov 2012 in comp.lang.javascript:

> Scott Sauyet wrote on 10 nov 2012 in comp.lang.javascript:
> 
>> ... makes it clear that what
>> he's looking for is, in this case, ["a", "b"], although quite possibly
>> the order of the resulting array wouldn't matter.  In other words,
>> he's not looking for the values which appear only once in the input
>> but rather one copy of each (possibly multiply occurring) value in the
>> input.
>> 
> 
> var arr = ["a", "b", "a"];
> 
> var i, j, obj = {};
> 
> for (i in arr)
>    obj[arr[i]] = 7;
> 
> for (j in obj)
>    document.write(j + ',');

Or in one loop:

var arr = ["a", "b", "a"];

var i, obj = {};

for (i in arr) {
   if (!obj[arr[i]]) 
      document.write(arr[i] + '<br>');
   obj[arr[i]] = true;
};



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Unique values of array Asen Bozhilov <asen.bozhilov@gmail.com> - 2012-11-08 05:00 -0800
  Re: Unique values of array Scott Sauyet <scott.sauyet@gmail.com> - 2012-11-08 06:10 -0800
    Re: Unique values of array Asen Bozhilov <asen.bozhilov@gmail.com> - 2012-11-08 06:26 -0800
  Re: Unique values of array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-11-08 21:21 +0100
    Re: Unique values of array Asen Bozhilov <asen.bozhilov@gmail.com> - 2012-11-08 13:06 -0800
      Re: Unique values of array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-11-09 02:26 +0100
  Re: Unique values of array Dr J R Stockton <reply1245@merlyn.demon.co.uk.invalid> - 2012-11-09 18:43 +0000
    Re: Unique values of array Scott Sauyet <scott.sauyet@gmail.com> - 2012-11-10 09:06 -0800
      Re: Unique values of array "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-11-10 20:19 +0100
        Re: Unique values of array "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-11-10 20:26 +0100
        Re: Unique values of array Scott Sauyet <scott.sauyet@gmail.com> - 2012-11-11 08:47 -0800
      Re: Unique values of array Dr J R Stockton <reply1245@merlyn.demon.co.uk.invalid> - 2012-11-11 16:52 +0000
        Re: Unique values of array Scott Sauyet <scott.sauyet@gmail.com> - 2012-11-12 05:10 -0800
          Re: Unique values of array Dr J R Stockton <reply1246@merlyn.demon.co.uk.invalid> - 2012-11-13 16:39 +0000
            Re: Unique values of array "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-11-14 10:21 +0100
            Re: Unique values of array Scott Sauyet <scott.sauyet@gmail.com> - 2012-11-14 04:32 -0800

csiph-web