To supplement what mscdex has already posted, here are two more articles:

http://dailyjs.com/2012/10/15/preparing-for-esnext/
https://brendaneich.com/2012/10/harmony-of-dreams-come-true/

You'l want to check out Set's. Enable them with `node --harmony` at 
runtime. Also, v8 doesn't support Set initialization with an Array. So 
you'll have to use .add() for every element. But they are about 6 times 
faster than using an Object lookup. Sort of like the following:

var the_set = new Set();
the_array.forEach(function(i) { the_set.add(i); });

As a side note, your syntax is incorrect. The forEach statement should look 
like the following:

the_array.forEach(function(i) { the_lookup[i] = true; });


On Tuesday, October 30, 2012 2:50:25 PM UTC-7, Felipe Gasper wrote:
>
> (Sorry, this is slightly OT.) 
>
> var the_array = ["foo", "bar", "baz", "qux"]; 
>
> //Is there a simpler way to do the following than what�s here? 
> var the_lookup = {}; 
> the_array.forEach( function(i) { the_lookup.i = true } ); 
>
> ======== 
>
> In Perl this is easy: 
> my @array = qw(foo bar baz qux); 
> my %lookup = map { $_ => 1 } @array; 
>
>
> Anything of the sort coming in JS, does anyone know? Maybe in some of 
> the newer ES5 goodies? 
>
> -FG 
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to