472,354 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Array in javascript

Hi.

Is it possible in javascript to operate on an array without knowing how mamy
elements it has?
What i want to do is sending an array to a script, and this script should
add all values from that array

Could you show me a little example how to do this?

Thanks.
Leszek
Feb 2 '06
104 16549
VK said the following on 2/9/2006 4:38 AM:

<snip>
Actually it was already answered right away why it is *not*
multi-dimensional array. But as I got more experience in having a
discussion with you, I'm not failing on this trick again. First of all,
dear Sir, you have to find out what *is* multi-dimensional array and
paste (or link) a working sample of multi-dimensional array, say
VBScript, C#, C++ or Java. And this has to come not from your own mind
or a freshly updated wiki article, but *at least* from an engine
producer page or (best of all) from some reputable higher education
establishment.
Let me give you a hint ok? Check it's length property.
Asking for definition while refusing to disclose your own one (so you
can always say: "That's not one!") *was* a great trick, but it is
currently explored to the end - with me at least.


It was no trick. When I ask loaded questions, I give a hint that it is a
loaded question. This was not one. If it were a true multi-dimensional
array, having more than one dimension, being non-linear, then the length
property will tell how many elements are in that array. It fails on
Richards code, and it fails on any "jagged array" code you post.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 15 '06 #101
Randy Webb wrote:
Richard Cornford said the following on 2/13/2006 2:54 AM:
Thomas 'PointedEars' Lahn wrote: <snip>
Yes, of course, with /that/ value (i.e. a "two-dimensional
array"; sorry, I know no better concise expression, maybe
you can enlighten me)
"Array of Arrays"
A concise expression of something is not necessarily limited to a
literal description of its structure.
I don't have any problem with labelling that construct
as a two-dimensional array.


You should as JS doesn't have a two-dimensional array :)


Javascript does not have a multi-dimensional Array, but the subject of
the description is a built structure so it is amenable to descriptions
that talk about the nature of the structure that was built. Calling this
structure two-dimensional is a reasonable expression of a characteristic
of the structure as created (it has two dimensions, in one sense).
Calling it an 'array' is also viable, the use of the lower case 'a'
implying the wider English meaning of 'array' rather than the specific
javascript 'Array'.

The actual applicability of any description to any given structure would
depend on why the structure was created. In this case an identical
structure could be implementing a 'tree' concept, where describing the
results as either two-dimensional or an array would be positively
counter-productive as those terms run contrary to the nature of a tree.
two-dimensional leads to multi-dimensional, neither of
which JS possesses.
And both of which may be significant characteristics of structures
created with javascript.
It's an array of arrays.


And it may also be any number of other things in addition. But being an
array of arrays means that it is certainly not a javascript Array.

Richard.


Feb 18 '06 #102
Richard Cornford said the following on 2/18/2006 1:04 PM:
Randy Webb wrote:
Richard Cornford said the following on 2/13/2006 2:54 AM:
Thomas 'PointedEars' Lahn wrote: <snip> Yes, of course, with /that/ value (i.e. a "two-dimensional
array"; sorry, I know no better concise expression, maybe
you can enlighten me) "Array of Arrays"


A concise expression of something is not necessarily limited to a
literal description of its structure.


That same reasoning can be applied to "jagged array", "hash array", and
"multi-dimensional array". And this entire thread (or most of it anyway)
has been spent on whether JS has a "jagged array" or not.

You can't have it both ways :)
I don't have any problem with labelling that construct
as a two-dimensional array.

You should as JS doesn't have a two-dimensional array :)


Javascript does not have a multi-dimensional Array, but the subject of
the description is a built structure so it is amenable to descriptions
that talk about the nature of the structure that was built. Calling this
structure two-dimensional is a reasonable expression of a characteristic
of the structure as created (it has two dimensions, in one sense).
Calling it an 'array' is also viable, the use of the lower case 'a'
implying the wider English meaning of 'array' rather than the specific
javascript 'Array'.


So you don't have problems with "jagged array", a "hash array" nor a
"multi-dimensional array" with respect to Javascript as long as the a is
lowercase?

The actual applicability of any description to any given structure would
depend on why the structure was created. In this case an identical
structure could be implementing a 'tree' concept, where describing the
results as either two-dimensional or an array would be positively
counter-productive as those terms run contrary to the nature of a tree.
two-dimensional leads to multi-dimensional, neither of
which JS possesses.


And both of which may be significant characteristics of structures
created with javascript.
It's an array of arrays.


And it may also be any number of other things in addition. But being an
array of arrays means that it is certainly not a javascript Array.


OK, then it is *not* a "two-dimensional array" as JS doesn't possess
one. Again, you can't have it both ways. It is either a cat or a dog,
not both :)

Otherwise, VK is going to bookmark this post and anytime he says JS has
a Jagged/Hash/Multi-Dimensional array and you say it doesn't, he is
going to point back here and say "A concise expression of something is
not necessarily limited to a literal description of its structure."

See the problem now?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 20 '06 #103
VK

Randy Webb wrote:
Otherwise, VK is going to bookmark this post and anytime he says JS has
a Jagged/Hash/Multi-Dimensional array and you say it doesn't, he is
going to point back here and say "A concise expression of something is
not necessarily limited to a literal description of its structure."


I already have a whole new bookmark section out of this thread. :-)
But keep going - I thought that maybe without my irritating presence
the thinking process would be more productive :-)

Feb 20 '06 #104
Randy Webb wrote:
Richard Cornford said the following on 2/18/2006 1:04 PM:
Randy Webb wrote:
Richard Cornford said the following on 2/13/2006 2:54 AM:
Thomas 'PointedEars' Lahn wrote: <snip>
> Yes, of course, with /that/ value (i.e. a "two-dimensional
> array"; sorry, I know no better concise expression, maybe
> you can enlighten me)
"Array of Arrays"


A concise expression of something is not necessarily limited
to a literal description of its structure.


That same reasoning can be applied to "jagged array",
"hash array", and "multi-dimensional array".


Yes it can, if a construct has been created to implement such concepts
then using such terms as a way of conveying some characteristic of the
construct is quite acceptable. Doing so may not absolutely precise and
may risk introducing wrong associations but it can also be a useful
shortcut to the rapid communication of ideas.
And this entire thread (or most of it anyway) has been spent
on whether JS has a "jagged array" or not.
As I have already said; if javascript can emulate anything then in one
sense it 'has' everything. Trying to apply that definition of javascript
'having' something would most likely inhibit an understanding of what
the javascript language is. A much more reasonable demarcation of what
javascript 'has' would be based on what 'is' by virtue of the nature
language as opposed to what can only be as a result of a construction or
emulation in javascript.

Of your short list only 'hash array' can be applied to something in
javascript without the need for a construction/emulation, as javascript
Objects do have qualities that resemble HashTables, etc. You may recall
that in the past reasonable arguments have been made in favour of
characterising javascript Objects as 'associative arrays' and
'HashTables'. I don't favour those usages as they do seem to directly
result in miss-associations where people expect the javascript Object to
be initially empty, support truly arbitrary keys and (with 'associative
array') have a - length - property that has a relationship with keys
used. But it is also undeniably the case that a value can be stored in a
javascript Object with a property name that can then be used as a key
for the retrieval of that value in the same way as a HashTable may be
used (there a just a stack of caveats that make drawing the parallel
insufficient as an explanation of the javascript Object).
You can't have it both ways :)
And I don't need to. This thread has been about whether it is
appropriate to apply the term 'jagged' to the javascript Array, in the
way that the terms 'dynamic' and 'sparse' can be applied to them.
Arguing that many labels can reasonably be applied to many things even
when those labels do not precisely describe the thing to which they are
attached, when those labels communicate something useful about the
object to which they are attached, is not inconstant with questioning
the applicability of a label to an object that is incapable of
exhibiting the quality named by the label. The javascript Array is
incapable of exhibiting 'jaggedness' so there can be no sense in which
it could be appropriate to characterise the javascript Array as
'jagged'.

The observation that it is possible to create, with javascript,
structures that may reasonably be labelled 'jagged arrays' or, for that
matter, 'multi-dimensional arrays' or 'trees' or 'maps' or whatever,
does not alter the nature of what the javascript Array is and so does
not make it reasonable to apply those labels to it.
I don't have any problem with labelling that construct
as a two-dimensional array.
You should as JS doesn't have a two-dimensional array :)


Javascript does not have a multi-dimensional Array, but the
subject of the description is a built structure so it is
amenable to descriptions that talk about the nature of the
structure that was built. Calling this structure two-dimensional
is a reasonable expression of a characteristic of the structure
as created (it has two dimensions, in one sense). Calling it an
'array' is also viable, the use of the lower case 'a' implying
the wider English meaning of 'array' rather than the specific
javascript 'Array'.


So you don't have problems with "jagged array", a "hash array"
nor a "multi-dimensional array" with respect to Javascript as
long as the a is lowercase?


I don't have a problem labelling a structure that satisfies the broad
definition of what an array is as an 'array', and arrays of arrays,
implemented in javascript often satisfy that definition (and javascript
Arrays also satisfy that definition). But because javascript has an
Array constructor with an upper case 'A' it is often felt that using the
upper case 'A' (at least away form the initial letter of a sentence) in
Array should be read as a statement about the special objects of the
type created with the Array constructor. That is; 'Array' should be used
as the name of the type of javascript object and 'array' used to assert
the quaintly of arrayness.

Objects and structures that do not exhibit 'arrayness', and objects that
may exhibit it but only by coincidence (such as trees), probably should
not be labelled as 'arrays'.

<snip>
And both of which may be significant characteristics of
structures created with javascript.
It's an array of arrays.


And it may also be any number of other things in addition.
But being an array of arrays means that it is certainly not
a javascript Array.


OK, then it is *not* a "two-dimensional array" as JS doesn't
possess one.


It is not a two-dimensional Array as javascript Arrays are
single-dimensional. It is a structure than exhibits arrayness and has
two-dimensions (at lest it has two dimensions if you are looking at its
arrayness, if you were looking at its treeness then any number of
dimensions are irrelevant).
Again, you can't have it both ways. It is either a cat
or a dog, not both :)
With a javascript construct what something is depends quite a lot on why
it was created. It could have been created to act as a
'multi-dimensional array', a 'jagged array' or a 'tree'. The same
structure could be any of them so it is up to the author to decide which
concept(s) were intended. Having decided what the concept being
implemented is a set of labels become appropriate to be used to talk
about the qualities of the structure created.
Otherwise, VK is going to bookmark this post and anytime he
says JS has a Jagged/Hash/Multi-Dimensional array and you
say it doesn't, he is going to point back here and say "A
concise expression of something is not necessarily limited
to a literal description of its structure."
VK has already convinced himself that he has won this argument, instead
of just making himself look like an irrational half-whit, so what he may
do in the future will likely be as irrational and irrelevant as his
posts here.
See the problem now?


I can see it, and name it. ;-)

Richard.
Feb 20 '06 #105

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

Similar topics

12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
13
by: Kevin | last post by:
Help! Why are none of these valid? var arrayName = new Array(); arrayName = new Array('alpha_val', 1); arrayName = ; I'm creating/writing the array on the server side from Perl, but I
5
by: Denis Perelyubskiy | last post by:
Hello, I need to make an array of elements accross forms. My javascript skills, as evident from this question, are rather rudimentary. I tried to make an associative array and index it with...
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
2
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
30
by: josh | last post by:
Hi all, what does it meaning that strange sintax (look at the object :) ? if I have i.e. array.length I can use array. and is it IE/Firefox compatible??
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...

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.