469,342 Members | 6,653 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

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 15943
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Sam Collett | last post: by
5 posts views Thread by Denis Perelyubskiy | last post: by
21 posts views Thread by yeti349 | last post: by
30 posts views Thread by josh | last post: by
2 posts views Thread by JJA | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.