Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion somewhat OT: creating a lookup hash in JS
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Felipe Gasper  
View profile  
 More options Oct 30 2012, 5:50 pm
From: Felipe Gasper <fel...@felipegasper.com>
Date: Tue, 30 Oct 2012 16:50:13 -0500
Local: Tues, Oct 30 2012 5:50 pm
Subject: somewhat OT: creating a lookup hash in JS
(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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.