473,507 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

one line "hash"

I have this:

var hash=new Array();
hash['a']='some_value';
hash['b']='some other value';

Whar do you call that in javascript?

I know it's possible to define this in one line, but I've forgotten how.
Something like:

var hash=new Array('a':'some value','b':'some other value') ???

Jeff
Jul 23 '05 #1
2 1569
On Thu, 10 Jun 2004 04:59:14 GMT, Jeff Thies wrote:
var hash=new Array();
hash['a']='some_value';
hash['b']='some other value'; Whar do you call that in javascript?
Array. With two new custom properties, called "a" and "b":

alert(hash.a);
alert(hash.b);
I know it's possible to define this in one line, but I've forgotten how.
Something like: var hash=new Array('a':'some value','b':'some other value') ???


You mean:

var hash={a:"some value",b:"some other value");

This is not an Array. This is an Object. And this syntax is called "Object
Initializer".

The previous code is equals to:

var hash=new Object();
hash.a="some value";
hash.b="some other value";

--
ZER0://coder.gfxer.web-designer/

~ "When you have eliminated the impossible, whatever remains,
however improbable, must be the truth." (S.H.)

Jul 23 '05 #2
> I have this:

var hash=new Array();
hash['a']='some_value';
hash['b']='some other value';

Whar do you call that in javascript?

I know it's possible to define this in one line, but I've forgotten how.
Something like:

var hash=new Array('a':'some value','b':'some other value') ???


You should be using an object for this application, not an array.

var hash = {a: "some_value", b: "some other value"};

And don't call it a hash. It makes you look like a Perl Boob.

See http://www.JSON.org
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1351
by: Trebor A. Rude | last post by:
I'm new to Perl (although I have about 7 years of C++ experience), and I was just wondering which of these two equivalent statements the group thinks is "better", and why: push @command, map...
2
5596
by: Liang | last post by:
Hi, I use "defined $r_libs->{$name}" to check first if a key exists in a hash table. But Perl gives a warning WHENEVER the key exists: "Use of uninitialized value". Would u please help to...
1
9887
by: Yimin Rong | last post by:
Does anyone know if there are any browsers where you must specify "#" as a prefix when setting the hash for the location? For example, the following would move to the intro section of the...
1
1300
by: bill.gates.com | last post by:
Dear Coders: I have a hashtable, Hashtable hash=new Hashtable(); and have a class, Pixels class Pixels {
21
13783
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
7
9971
by: Clint Herron | last post by:
Howdy! I posted this question on CSharpCorner.com, but then realized I should probably post it on a more active newsgroup. This will be my only cross-post. I'm creating a game engine, and...
18
1789
by: beginner | last post by:
Hi All. I'd like to do the following in more succint code: if k in b: a=b else: a={} b=a
1
1964
by: Dad | last post by:
Hi, A number of interfaces, e.g., IEqualityComparer, include GetHashCode. When does it need to be implemented? I usually just return 0 or 1. Thanks, Gary
13
11990
by: Kurda Yon | last post by:
Hi, I found one example which defines the addition of two vectors as a method of a class. It looks like that: class Vector: def __add__(self, other): data = for j in range(len(self.data)):...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.