473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

problems with associative arrays

Hi,

I'm facing issues with using associative arrays in non-IE browsers. In
particular, I have code like the following:

var IDToAddress = new Array();
IDToAddress['1000000'] = 'apple tree lane, mars';
IDToAddress['2000100'] = 'orchard street, venus';
The keys used in this array are all strings, but each key is actually
just a v. large integer e.g. '1000000'. There are several hundred such
key-value pairs that make up this array.

This works fine in IE, but other browsers simply hang, using up huge
amounts of memory. It appears that not all browsers handle such
associative arrays well - whose keys are large numbers represented as
strings. Has anyone faced similar problems, and are there work-arounds?

thanks
Nagender

Sep 30 '05 #1
3 1602
On 30 Sep 2005 00:33:38 -0700, nk******@gmail.com wrote:
var IDToAddress = new Array();
IDToAddress['1000000'] = 'apple tree lane, mars';
IDToAddress['2000100'] = 'orchard street, venus';


Use simply object, not Array:

var IDToAddress=new Object();

IDToAddress['1000000'] = 'apple tree lane, mars';
IDToAddress['2000100'] = 'orchard street, venus';

with object initializer:

ex. 1
var IDToAddress={};

IDToAddress['1000000'] = 'apple tree lane, mars';
IDToAddress['2000100'] = 'orchard street, venus';

ex. 2
var IDToAddress={
'1000000':'apple tree lane, mars',
'2000100':'orchard street, venus'
}

IDToAddress['key']="something";

You can reference the properties with dot notation or squadre bracket
notation:

alert(IDToAddress.key);
alert(IDToAddress["key"]);

This works for all object:

window["alert"]("hello world");
window.alert("hello world");
And you can iterate the properties with for..in statement.

In addition, you can find on net a lot of "classes" for more complex hash
objects.

I hope it helps, and sorry for my english.

--
~ Io non soffro di pazzia, ne godo ogni minuto.
(I don't suffer from insanity, I enjoy every minute of it)

Sep 30 '05 #2
1. All keys are stored as strings, even with a[1], the 1 is stored as
a string.

2. I believe I read in a previous post that for some browsers, if you
set an integer index on an Array, it will fill in every undefined
index position up to it with blanks, whereas IE leaves previous
undefined index positions as undefined.

3. You could also look at putting a non digit prefix in to the key,
e.g. IDToAddress['PREFIX2000100']

Sep 30 '05 #3
nk******@gmail.com wrote:
Hi,

I'm facing issues with using associative arrays in non-IE browsers. In
particular, I have code like the following:

var IDToAddress = new Array();
IDToAddress['1000000'] = 'apple tree lane, mars';
IDToAddress['2000100'] = 'orchard street, venus';
The keys used in this array are all strings, but each key is actually
just a v. large integer e.g. '1000000'. There are several hundred such
key-value pairs that make up this array.

This works fine in IE, but other browsers simply hang, using up huge
amounts of memory. It appears that not all browsers handle such
associative arrays well - whose keys are large numbers represented as
strings. Has anyone faced similar problems, and are there work-arounds?


You may find this post (and some of the rest of the thread) useful:

<URL:http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ec127472a6d9f417/f59d2969df16c937?q=array+length+VK&rnum=1&hl=en#f5 9d2969df16c937>

--
Rob
Sep 30 '05 #4

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

Similar topics

11
by: Stefan Richter | last post by:
Hi, I want to create an associative Array with a PHP variable (article ID) as Key and another associative array as it's value. How do I instanciate it, how can I fill it? I want something...
27
by: Abdullah Kauchali | last post by:
Hi folks, Can one rely on the order of keys inserted into an associative Javascript array? For example: var o = new Object(); o = "Adam"; o = "Eve";
6
by: mark4asp | last post by:
Suppose I have the following code. It functions to randomly select a city based upon the probabilities given by the key differences in the associative array. . Eg. because the key difference...
4
by: Robert | last post by:
I am curious why some people feel that Javascript doesn't have associative arrays. I got these definitions of associative arrays via goggle: Arrays in which the indices may be numbers or...
8
by: Derek Basch | last post by:
Is there any way to associate name/value pairs during an array initialization? Like so: sType = "funFilter" filterTypeInfo = ; filterTypeInfo = new Array("type" : sType); I can do it using...
7
by: Robert Mark Bram | last post by:
Hi All! How do you get the length of an associative array? var my_cars= new Array() my_cars="Mustang"; my_cars="Station Wagon"; my_cars="SUV"; alert(my_cars.length);
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
11
by: Bosconian | last post by:
I'm trying to output the contents of an array of associative arrays in JavaScript. I'm looking for an equivalent of foreach in PHP. Example: var games = new Array(); var teams = new...
14
by: julie.siebel | last post by:
I've been wrestling with a really complex page. All the data is drawn down via SQL, the page is built via VBScript, and then controlled through javascript. It's a page for a travel company that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.