problems with associative arrays

N

nkparimi

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
 
Z

ZER0

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.
 
B

Baconbutty

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']
 
R

RobG

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...array+length+VK&rnum=1&hl=en#f59d2969df16c937>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top