473,809 Members | 2,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

arrays and objects

ABC

I am not a javascript guru or anything so I was wondering if someone
could tell me what the code below is doing. Is it creating a
multidimensiona l array? Would it be better to create an object?

function addKey(commentK ey, codeHexa, gotoPage, funcToLoad)
{

aKey[nbrKey] = new Array();
aKey[nbrKey]["comment"] = commentKey;
aKey[nbrKey]["codeHexa"] = codeHexa;
aKey[nbrKey]["gotoPage"] = gotoPage;
aKey[nbrKey][0] = funcToLoad;
nbrKeys++;
}

Thanks

ABC
Jul 20 '05 #1
3 1988
"ABC" <bc*******@imag ictv.com> wrote in message
news:3f******** ******@allnews. nbnet.nb.ca...
... I was wondering if someone could tell me what
the code below is doing.
The function creates a new Array and assigns it to a property of an
object (global) called - aKey - . Which is probably an Array itself as
it is indexed with the (global) variable - nbrKeys - which is probably a
number (integer) as it is subject to mathematical (post increment)
operations.

The function then creates a number of named properties of the array and
assigns values to them. JavaScript Arrays are objects (with extra
functionality added) and can have named properties added to them at any
point. Finally a value is assigned to the array element at index 0 and
the - nbrKeys - variable in incremented.
Is it creating a multidimensiona l array?
Not really. JavaScritp does not do multidimensiona l arrays as such, it
can do Arrays of Arrays (which is similar, even practically identical in
some cases). Assuming that - aKey - is an Array to start with assigning
an Array to one of its elements will make it an Array of Arrays (but
values assigned elsewhere in the code cannot be determined form this
function example so the - aKey - array may contain references to any
objects of any type and any primitive values in its other elements).
Would it be better to create an object?

<snip>

Impossible to say from just this code. As it is the new Array assigned
as an indexed element of - aKey - is having values assigned to its
indexed elements so it is possible that its Array-ness is being
exploited elsewhere in the code and an Array is the appropriate object
to be using.

Generally, if you want Array-like behaviour (indexing by integer) then
an Array is the appropriate object to use. If you want to index by name
only then a plain object would usually be better and if you want to do
both (as in this example) then you have a range of choices including
exploiting the Object-ness of an Array to provide named properties.

Richard.
Jul 20 '05 #2
Thanks for that very detailed explanation, I realize it is sometimes
hard to answer a question with a small snippet of code. I am going
through a lot of javascript code trying to optimize a web application
running on an embedded web server, the web app has a lot of
javascript. The processor this web server is running on is slow and
handles floating point poorly(hard to explain that). If you have any
ideas or websites to visit to help with javascript code optimization
please let me know.

Again Thanks,

ABC

On Sat, 20 Sep 2003 13:33:34 +0100, "Richard Cornford"
<Ri*****@litote s.demon.co.uk> wrote:
"ABC" <bc*******@imag ictv.com> wrote in message
news:3f******* *******@allnews .nbnet.nb.ca...
... I was wondering if someone could tell me what
the code below is doing.


The function creates a new Array and assigns it to a property of an
object (global) called - aKey - . Which is probably an Array itself as
it is indexed with the (global) variable - nbrKeys - which is probably a
number (integer) as it is subject to mathematical (post increment)
operations.

The function then creates a number of named properties of the array and
assigns values to them. JavaScript Arrays are objects (with extra
functionalit y added) and can have named properties added to them at any
point. Finally a value is assigned to the array element at index 0 and
the - nbrKeys - variable in incremented.
Is it creating a multidimensiona l array?


Not really. JavaScritp does not do multidimensiona l arrays as such, it
can do Arrays of Arrays (which is similar, even practically identical in
some cases). Assuming that - aKey - is an Array to start with assigning
an Array to one of its elements will make it an Array of Arrays (but
values assigned elsewhere in the code cannot be determined form this
function example so the - aKey - array may contain references to any
objects of any type and any primitive values in its other elements).
Would it be better to create an object?

<snip>

Impossible to say from just this code. As it is the new Array assigned
as an indexed element of - aKey - is having values assigned to its
indexed elements so it is possible that its Array-ness is being
exploited elsewhere in the code and an Array is the appropriate object
to be using.

Generally, if you want Array-like behaviour (indexing by integer) then
an Array is the appropriate object to use. If you want to index by name
only then a plain object would usually be better and if you want to do
both (as in this example) then you have a range of choices including
exploiting the Object-ness of an Array to provide named properties.

Richard.


Jul 20 '05 #3
<fi*********@ho tmail.com> wrote in message
news:jv******** *************** *********@4ax.c om...
Thanks for that very detailed explanation, I realize it is sometimes
hard to answer a question with a small snippet of code. I am
going through a lot of javascript code trying to optimize a web
application running on an embedded web server, the web app
has a lot of javascript. The processor this web server is running
on is slow and handles floating point poorly(hard to explain that).
If you have any ideas or websites to visit to help with javascript
code optimization please let me know.


You are not very clear about the set-up here. Is the JavaScript that you
wish to optimise client-side or server-side. I assume it is server-side
as otherwise the floating point performance on the server would not be
an issue. So is this JScript ASP or another server-side JavaScript?

In either case I probably cannot help much as I do my server side work
in Java and most of what I know about optimising JavaScript is related
to web browsers as an environment. But that doesn't mean that you won't
get help from someone if you provide some more detail.

Richard.
Jul 20 '05 #4

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

Similar topics

5
3115
by: Gent | last post by:
I have two questions which are very similar: Is it possible to return an object in C++. Below is part of my code for reference however I am more concerned about the concept. It seems like the function below is returning a pointer to pointers who are GUID. I am trying to write a wrapper to use in my VB code and what I would prefer to do is be able to return an array of GUID. I remember (not sure) that the concept of arrays does not really...
34
4250
by: Christopher Benson-Manica | last post by:
If an array is sparse, say something like var foo=; foo=4; foo='baz'; foo='moo'; is there a way to iterate through the entire array? --
11
2290
by: Soeren Sonnenburg | last post by:
Hi all, Just having started with python, I feel that simple array operations '*' and '+' don't do multiplication/addition but instead extend/join an array: a= >>> b= >>> a+b
8
7703
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 this: sType = "String"
79
3439
by: Me | last post by:
Just a question/observation out of frustration. I read in depth the book by Peter Van Der Linden entitled "Expert C Programming" (Deep C Secrets). In particular the chapters entitled: 4: The Shocking Truth: C Arrays and Pointers Are NOT the Same! 9: More about Arrays 10: More about Pointers What blows me out of the water is the fact that 'every' programmer
8
2253
by: masood.iqbal | last post by:
All this time I was under the illusion that I understand the concept of multi-dimensional arrays well ---- however the following code snippet belies my understanding. I had assumed all along that a declaration like: int intArray means that there is an array of pointers to int with a size of 5, each of whose elements is an array of int with a size of 3. This definition seemed intuitive to me since a declaration like
5
4657
by: Alan Howard | last post by:
We're getting "ERROR (0x8007000E) Not enough storage is available to complete this operation" errors on a fairly large, busy ASP/SQL Server web site. The error is being thrown on a line calling oRs.GetRows() on one of our busiest pages. The array returned from the GetRows() call will be 'cleaned up' when the page goes out of scope, but I wonder if we should be calling Erase specifically after the last usage to explicitly free allocated...
25
2515
by: Jack | last post by:
Hi, Is there a general solution for the following problem: I have an array of instances of class B. Class B is publicly derived from class A. Then I have a class named Buffer that generally takes care of allocating and deallocating arrays. Class Buffer knows only that the objects contained in its internal array are derived from class A but not that they are exactly of type B, so Buffer has a member variable of type A* that points at...
41
4990
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 the hash are alphabetically sorted if the key happens to be alpha numeric. Which I believe makes sense because it allows for fast lookup of a key.
5
2213
by: M. Fisher | last post by:
Pardon my ignorance here... I have created arrays such as: var SDET_Lab130= new Array(); SDET_Lab130 = new Array(); SDET_Lab130 = ; SDET_Lab130 = ; SDET_Lab130 = ; SDET_Lab130 = ; SDET_Lab130 = ;
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10643
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10378
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10121
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4333
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 we have to send another system

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.