Re: Adding several key-value pairs at a time to Dictionary object
- From: "dotNuttah" <a@xxx>
- Date: Sun, 7 May 2006 01:54:28 +0100
Anthony Jones wrote:
"Randy Webb" <HikksNotAtHome@xxxxxxx> wrote in message
news:6aqdnS9sPOqICMfZnZ2dnUVZ_v6dnZ2d@xxxxxxxxxxxxxx
Anthony Jones said the following on 5/4/2006 5:43 PM:
"Randy Webb" <HikksNotAtHome@xxxxxxx> wrote in message
news:t8GdnXqCgqYc3sfZRVn-tA@xxxxxxxxxxxxxx
Anthony Jones said the following on 5/4/2006 9:44 AM:
"Randy Webb" <HikksNotAtHome@xxxxxxx> wrote in message"Close enough", yes, but an Associative Array? No. In fact, the
news:AM6dnTtRyM5dBMTZnZ2dnUVZ_uidnZ2d@xxxxxxxxxxxxxx
K said the following on 5/3/2006 3:01 PM:var o = new Object()
Hi!Where is the data for the dictionary coming from? Where it is
Here is a question I have: I am loading a large number of
dictionary entries into a dictionary ActiveX object in a JS
file. This means I repeat the statement
MyDictionary.Add("key n","value n");
thousands of times. Does anyone know whether its possible to
fill a dictionary by any other syntax?
coming from will give you some insight on the best way to create
the Dictionary object from it.
Or is javascript's associative arrays better for this purpose??Javascript doesn't have an associative array.
o['MyKey1'] = 'Hello'
o['MyKey2'] = 'World'
Gets close enough for most uses as long as you don't also need to
access items by an ordinal index.
above is not even an Array. Even converting it to an Array:
http://en.wikipedia.org/wiki/Associative_array
That one is dead wrong with regards to JS, and another example of
why I have a lack of trust of anything I read in a wiki.
Really?? What's wrong with it exactly?
http://www.comp.leeds.ac.uk/Perl/associative.html
PERL has an Associative Array, as does PHP, but that doesn't change
the fact the JS doesn't.
The purpose of posting these links is to provide a general idea of
what an Associative Array is.
http://www.nist.gov/dads/HTML/assocarray.html
That one is irrelevant to JS.
Again for the purpose of defining an associative array.
I could go on but I think the point is made.
If your point is that I am right and that Javascript doesn't have an
Associative Array,
then yes, your point is made. If you think your point
that you think JS has an Associative Array is made, then no, you are
incorrect. JS doesn't have an Associative Array.
I didn't actually say that it did. But you saw fit post a response
as if I did.
The code I posted showed that, very clearly. Here it is again:
var o = new Array()
o['MyKey1'] = 'Hello'
o['MyKey2'] = 'World'
If o were an Associative Array, with its corresponding length
property, then the length would be 2. It isn't, the above code gives
a length, correctly, of 0.
Agreed. You don't get to discover how many entries you have in the
array which is pretty fundemental to anything that wants to call
itself an array.
Now, does it act similar to an Associative Array? Sure. But that
doesn't make it an Associative Array, it makes it an Array/Object
that behaves, mildly, like an Associative Array.
Pretty darn close enough for many applications. In a lot of cases
you don't need or want to access the content by ordinal and how many
entries are present is also irrelevant. In these cases Object will
do fine.
This entire subject has been discussed, to death, inhttp://www.JavascriptToolbox.com/bestpractices/
comp.lang.javascript, you can search the archives and read about it.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup
weekly Javascript Best Practices -
Blah, blah, blah, lolol
Assuming, of course, that K actually needs the associativity...
function AssocArray()
{
}
AssocArray.prototype.Add = function (valueA, valueB)
{
this [vValueA] = vValueB;
this [vValueB] = vValueA;
this [this.length] = vValueA; // If indexing is desired and no values
are numeric in nature.
this.count = this.length // If you prefer this property.
}
implementer: Hey, Javascript's got a very primitive associative array.
Woohoo!! :-)))
critic: Yeah, but it's not built in. z:-|
implementer: Oh, that makes it useless then, I guess. :-(((
critic: Well, no, that's not what I was saying.
implementer: Hey, Javascript's got a very primitive associative array.
Woohoo!! :-)))
critic: Philistine.
DotNuttah: LOLOL
.
- Follow-Ups:
- Re: Adding several key-value pairs at a time to Dictionary object
- From: Anthony Jones
- Re: Adding several key-value pairs at a time to Dictionary object
- References:
- Re: Adding several key-value pairs at a time to Dictionary object
- From: Randy Webb
- Re: Adding several key-value pairs at a time to Dictionary object
- From: Anthony Jones
- Re: Adding several key-value pairs at a time to Dictionary object
- From: Randy Webb
- Re: Adding several key-value pairs at a time to Dictionary object
- From: Anthony Jones
- Re: Adding several key-value pairs at a time to Dictionary object
- From: Randy Webb
- Re: Adding several key-value pairs at a time to Dictionary object
- From: Anthony Jones
- Re: Adding several key-value pairs at a time to Dictionary object
- Prev by Date: Re: Javascript Array sort with Comparator in IE6 very slow
- Next by Date: Re: Adding several key-value pairs at a time to Dictionary object
- Previous by thread: Re: Adding several key-value pairs at a time to Dictionary object
- Next by thread: Re: Adding several key-value pairs at a time to Dictionary object
- Index(es):
Relevant Pages
|