473,289 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 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 #1
104 16810
Leszek wrote:
Is it possible in javascript to operate on an array without knowing how
mamy elements it has?
Of course. This is what the e.g. `length' property of Array objects is for.
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?


Depends on what you mean by "sending an array to a script" (which array,
which script, client-side or server-side, send from where to where?) and by
"script should add all values from that array" (add from where exactly to
which?)
PointedEars
Feb 2 '06 #2
VK

Leszek wrote:
Hi.

Is it possible in javascript to operate on an array without knowing how mamy
elements it has?
JavaScript array is Dynamic Sparse Jagged Array. That can be too much
of adjectives for one time :-) but the first one means that can add new
elements to array without ReDim / resize() it.

var myArray = new Array(); // 0 elements
myArray[0] = 0;
....
....
myArray[1000] = 1000;

About other adjectives (and about JavaScript arrays at whole) you can
read at:
<http://www.geocities.com/schools_ring/ArrayAndHash.html>
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?


As it was pointed out it depends on how and in what form are you
getting the original data for your array.

Feb 2 '06 #3
Leszek
Is it possible in javascript to operate on an array without knowing how mamy
elements it has?


I don't think, there is no function like 'map' or 'apply'. However, they
are not difficult to implement because you always know the size of an
array: array.length;

--
My desktop is worth a million of dollars. Put an icon on it.
http://www.milliondollarscreenshot.com/
Feb 2 '06 #4
VK wrote:
Leszek wrote:
Is it possible in javascript to operate on an array without knowing how
mamy elements it has?
JavaScript array is Dynamic Sparse Jagged Array. That can be too much
of adjectives for one time :-)


But I am sure you can invent more just to cover your lack of knowledge and
understanding of the basics.
but the first one means that can add new
elements to array without ReDim / resize() it.

var myArray = new Array(); // 0 elements
myArray[0] = 0;
...
...
myArray[1000] = 1000;
You did not answer the question of the OP _at all_. Figures.
About other adjectives (and about JavaScript arrays at whole) you can
read at:
<http://www.geocities.com/schools_ring/ArrayAndHash.html>


This text contains a lot of, if not consists mainly of, factually incorrect
information, presented as being the truth despite of that. Readers are
strongly recommended to ignore it, to handle all statements of its author
regarding (proper) software development with extreme care, and to read
previous discussions on the subject instead.

<URL:http://groups.google.com/groups?as_q=Array&as_ugroup=comp.lang.javascript&s coring=d&filter=0>
<URL:http://groups.google.com/groups?as_uauthors=VK&as_ugroup=comp.lang.javascri pt&scoring=d&filter=0>
PointedEars
Feb 2 '06 #5
Leszek wrote:
Hi.

Is it possible in javascript to operate on an array without knowing how mamy
elements it has?
Yes.
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?


This is the smallest example I could write:

<html><head><title>Little Sum Function</title></head>
<body><script type="text/javascript">
function s(a){return Function('return '+a.join('+'))()}
document.write(s([1,654,2,5,489,51,3851,681,32,5,0]))
</script></body></html>

Feb 2 '06 #6
VK

Thomas 'PointedEars' Lahn wrote:
VK wrote:
Leszek wrote:
Is it possible in javascript to operate on an array without knowing how
mamy elements it has?


JavaScript array is Dynamic Sparse Jagged Array. That can be too much
of adjectives for one time :-)


But I am sure you can invent more just to cover your lack of knowledge and
understanding of the basics.


JavaScript array is Dinamic, is Sparse and is Jagged. These three core
features are important to know to operate properly with arrays and get
expected results.

<http://www.geocities.com/schools_ring/ArrayAndHash.html> is the only
one known (to me at least) resource there all three features along with
other information would be named and illustrated properly: all within
the same page. Unfortunately (after careful reading and searching) this
is still the only resource I can endorse for JavaScript array
information.

It should be updated though by removing some no so relevant part at the
bottom and by adding new array methods from JavaScript 1.6 (Firefox 1.5)

Feb 2 '06 #7
Jambalaya wrote:
Leszek wrote:
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?


This is the smallest example I could write:

<html>
<head><title>Little Sum Function</title></head>
<body><script type="text/javascript">
function s(a){return Function('return '+a.join('+'))()}
document.write(s([1,654,2,5,489,51,3851,681,32,5,0]))
</script></body></html>


Nice[1] :)

Not shorter, but Valid:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"><head><meta
http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title>Little Adder</title></head><script
type="text/javascript">document.write(Function("return "
+[1,654,2,5,489,51,3851,681,32,5,0].join("+"))());</script>
Regards,
PointedEars
___________
[1] especially because there is no evil[tm] eval()
Feb 2 '06 #8
Jambalaya wrote on 02 feb 2006 in comp.lang.javascript:
This is the smallest example I could write:

<html><head><title>Little Sum Function</title></head>
<body><script type="text/javascript">
function s(a){return Function('return '+a.join('+'))()}
document.write(s([1,654,2,5,489,51,3851,681,32,5,0]))
</script></body></html>


<script type="text/javascript">
alert(eval([1,654,2,5,489,51,3851,681,32,5,0].join('+')));
</script>

or for the (eval==evil)-ers:

<script type="text/javascript">
var b=0,a=[1,654,2,5,489,51,3851,681,32,5,0],z=a.length;
while(z)b+=a[--z];alert(b)
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 2 '06 #9
Leszek wrote:
[...]
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?


// An array of numbers, some as strings
var A = [2,'5',8,'2',4];

// A function that adds all the elements of an array
function addEm(X)
{
var i = X.length;
var sum = 0;
while(i--) sum += +X[i];
return sum;
}

// Show it in action
alert( addEm(A) );
If there is any chance that some of the elements might not be numbers,
then that should be checked before attempting addition:

var A = [2,'blah','5',8,2,4];

function addEm(X)
{
var x, i = X.length;
var sum = 0;
while(i--) {
x = +X[i];
if ( !isNaN(x) ) sum += x;
}
return sum;
}

--
Rob
Feb 2 '06 #10
Leszek wrote:
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
I think the previous responses over looked the use of
for( var n in array ) {} as a method for iterating over an array.
Could you show me a little example how to do this?


function test( names )
{
for( var name in names )
{
// do something.
}
}

--
Ian Collins.
Feb 3 '06 #11
VK

Ian Collins wrote:
I think the previous responses over looked the use of
for( var n in array ) {} as a method for iterating over an array.
Could you show me a little example how to do this?


function test( names )
{
for( var name in names )
{
// do something.
}
}


for-in loop has nothing to do with *array*, it's an iterator over
enumerable properties of object.

Try this to understand the difference:

var arr = [1,2,3];
arr.foo = 'bar';

for (var i=0; i<arr.length; i++) {
alert(arr[i]);
}

for (var p in arr) {
alert(p);
}

Feb 3 '06 #12
VK wrote:
Thomas 'PointedEars' Lahn wrote:
VK wrote: <snip>
JavaScript array is Dynamic Sparse Jagged Array. That
can be too much of adjectives for one time :-)
But I am sure you can invent more just to cover your lack
of knowledge and understanding of the basics.


JavaScript array is Dinamic, is Sparse and is Jagged.


Can you justify applying the term "jagged" to a javascript array when
they can only have a single dimension?

<snip> <http://www.geocities.com/schools_ring/Array ... <snip> ... . Unfortunately (after careful reading and searching)
this is still the only resource I can endorse for JavaScript
array information.

<snip>

Your willingness to endorse your own page is not significant (beyond the
observation that your tendency to always choose the worst option
available means that your endorsement may be taken as a condemnation by
reasoning observers). The important consideration is whether it could be
endorsed by anyone who actually understands javascript. You have tried
to get such an endorsement from contributors to this group and the
reactions you got were anything but an endorsement.

Richard.
Feb 3 '06 #13
VK

Richard Cornford wrote:
Can you justify applying the term "jagged" to a javascript array when
they can only have a single dimension?
This is exactly the case with JavaScript array wich is a single
dimension array when looking at it "from the top". But it can have
other arrays as its elements. Array of arrays is called in the
programming "jagged array".
We may of course continue to stay on the position that nothing of
regular programming is applicable to JavaScript - neither in terms nor
in technology :-)
In such case array of arrays is called "jagged" everywhere but in
JavaScript it's just "array of arrays" :-)

Jagged nature of JavaScript array is really important to know and
understand for say array sorting.
Your willingness to endorse your own page is not significant (beyond the
observation that your tendency to always choose the worst option
available means that your endorsement may be taken as a condemnation by
reasoning observers). The important consideration is whether it could be
endorsed by anyone who actually understands javascript. You have tried
to get such an endorsement from contributors to this group and the
reactions you got were anything but an endorsement.


This article is not perfect and I willing to update it and make it even
more transparent. I would like to link some reputable public source
instead from say Mozilla.org or MSDN or IBM.com etc. Unfortunately
anything of this kind is either incomplete, or confusing or (more
often) factually wrong.

Feb 3 '06 #14
VK wrote:
Ian Collins wrote:
I think the previous responses over looked the use of
for( var n in array ) {} as a method for iterating over an array.

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


function test( names )
{
for( var name in names )
{
// do something.
}
}

for-in loop has nothing to do with *array*, it's an iterator over
enumerable properties of object.

True, I've been using too many objects as associative arrays....

--
Ian Collins.
Feb 3 '06 #15
VK wrote:
Richard Cornford wrote:
Can you justify applying the term "jagged" to a javascript
array when they can only have a single dimension?
This is exactly the case with JavaScript array wich is a single
dimension array when looking at it "from the top".


Javascript has single dimension arrays however you look at them.
But it can have other arrays as its elements. Array of arrays
is called in the programming "jagged array".
No, the concept of a jagged array can only be implemented in javascript
with an array of arrays, but that does not make the javascript array
jagged. Indeed, the very fact that you must have more than one Array in
order to implement the concept of 'jagged' means that the term _cannot_
apply to a javascript Array (singular).

And "in the programming" a 'jagged array' is not an array of arrays, as
is easily demonstrated by the Java array, which is a single array that
is multidimensional and jagged.
We may of course continue to stay on the position that nothing
of regular programming is applicable to JavaScript - neither
in terms nor in technology :-)
We? You are exclusively and personally responsible for your own
incoherent ramblings.
In such case array of arrays is called "jagged" everywhere
but in JavaScript it's just "array of arrays" :-)
Everywhere? I think you will find that the term 'jagged' will normally
be applied with discrimination beyond your comprehension.
Jagged nature of JavaScript array is really important to know
and understand for say array sorting.
So it is important to understand that the javascript array is a single
dimension array and so cannot be 'jagged'.
Your willingness to endorse your own page is not significant
(beyond the observation that your tendency to always choose
the worst option available means that your endorsement may
be taken as a condemnation by reasoning observers). The
important consideration is whether it could be endorsed by
anyone who actually understands javascript. You have tried to
get such an endorsement from contributors to this group and
the reactions you got were anything but an endorsement.


This article is not perfect and I willing to update it and make
it even more transparent.


BODY {
display:none;
}
I would like to link some reputable public source instead
from say Mozilla.org or MSDN or IBM.com etc.
Bad sources of information often try to gain credibility by linking to
'reputable public sources'. What is up, you cannot find anything on
these sites that doesn't directly contradict your page?
Unfortunately anything of this kind is either incomplete, or
confusing or (more often) factually wrong.


LOL. You own page is incomplete, confusing and factually wrong. That is
precisely what was said of it when you attempted to get this group to
endorse it.

On the other hand, one of the advantages of your page is that some of
the 'factually wrong' is so obvious that only the complete novice is
likely to give any credence to the rest of its text.

Richard.
Feb 3 '06 #16
VK

Richard Cornford wrote:
same old story


All arguments has been spelled many times over the last year.
You are welcome to give array-related advises from your point of view:
and I reserve the same for mine.

Eventually only the practice (who's picture allow to create effective
predictable code) is the way to check a theory. A theory in
contradiction with the practical experience is worthless IMHO.

Feb 3 '06 #17
VK

Richard Cornford wrote:
No, the concept of a jagged array can only be implemented in javascript
with an array of arrays, but that does not make the javascript array
jagged. Indeed, the very fact that you must have more than one Array in
order to implement the concept of 'jagged' means that the term _cannot_
apply to a javascript Array (singular).


Sorry for making addons to my post, but there is a logical (not
pragrammatical) error in the above reasonning:

Neither C++ or Java array are *obligated* to be multi-dimensional. In
any language I can perfectly create a simple single-dimention array.
Applying your own thesis: "The very fact that you must have more than
one dimension in order to implement the concept of `multi-dimensional'
means that the term _cannot_ apply to a C++ array (singular)."

This logical casus can be solved is we realize that "milti-dimensional"
vs. "jagged" are applied to the *model potention* and not to a
particular given array X, Y or Z.

Feb 3 '06 #18
VK wrote:
Richard Cornford wrote:
No, the concept of a jagged array can only be implemented in
javascript with an array of arrays, but that does not make
the javascript array jagged. Indeed, the very fact that you
must have more than one Array in order to implement the
concept of 'jagged' means that the term _cannot_ apply to a
javascript Array (singular).
Sorry for making addons to my post, but there is a logical
(not pragrammatical) error in the above reasonning:


It is partly the fact that you cannot recognise logical errors that
leads me to question your rationality.
Neither C++ or Java array are *obligated* to be multi-dimensional.
While javascript Arrays cannot be multi-dimensional.
In any language I can perfectly create a simple
single-dimention array. Applying your own thesis:
"The very fact that you must have more than
one dimension in order to implement the concept of
`multi-dimensional' means that the term _cannot_ apply
to a C++ array (singular)."
In that case the parallel statement is that because you have to have
more than one dimension before something is multi-dimensional then a
_dimension_ (singular) cannot be multi-dimensional. That is, the term
'multi-dimensiton' cannot be applied to a dimension.

The term is applicable to arrays in certain languages because they have
the potential to have multiple dimensions, whether the actually do or
not (and the Java array has the potential to be jagged as well).

It is like stating that the javascript Array is a sparse array. Actual
array instances do not need to be sparse (in the sense of having fewer
than - array.length - 'array index' properties), but the configuration
of an instance does not alter the nature of the javascript Array.
This logical casus can be solved is we realize that
"milti-dimensional" vs. "jagged" are applied to the
*model potention* and not to a particular given array
X, Y or Z.


The javascript array has no potential to have multiple dimensions and so
no potential to be 'jagged'. Both concepts can be successfully
implemented/emulated with javascript but that can not be done with a
single javascript Array, and so the terms 'multi-dimensional' and
'jagged' are not applicable as characteristics of a javascript Array.

Richard.
Feb 3 '06 #19
VK wrote:
Richard Cornford wrote:
same old story
All arguments has been spelled many times over the
last year.


Yes they have, and you have presented no reasoned counter argument, only
the stubborn refusal to pay any attention.
You are welcome to give array-related advises from
your point of view: and I reserve the same for mine.
Your ability (and right) to post any nonsense you choose cannot be
denied. But your should have no expectation of being allowed to do so
without being criticised for doing so.

And I am subject to the same consideration. If I posted nonsense,
falsehoods and bad advice I expect (and even want) to be corrected and
criticised for doing so. But that doesn't seem to happen often; not
because I am intrinsically or inherently correct but because in the past
I have paid attention to such comments and learnt form them.

Initial ignorance of any subject is inevitable and as people learn they
make mistakes, but most learn form, instead of repeating, their
mistakes.
Eventually only the practice (who's picture allow to create
effective predictable code) is the way to check a theory.
But you don't write effective predictable computer code. You write a
chaotic mush half thought-out reasoning and pure voodoo. The last piece
of 'full working' code you posted to this group earned the epithet "the
most bizarre and obtuse storage method I've ever witnessed", with good
reason, and demonstrated a basic lack of understanding of standard
language constructs.
A theory in contradiction with the practical experience
is worthless IMHO.


A theory that is contradicted by reality is false, but it takes some
familiarity with testing and analysis methodologies to identify a real
contradiction. That perverse personal mental process that you like to
label 'logic' seems to significantly restrict your ability to create and
apply tests, or analyse the results. A fact that should have been
sufficiently flagged when you posted earlier in the week that your had
spent two months testing Mozilla browsers and concluded that they did
not support - document.styleSheets -, when they have done so since their
beta versions at least.

The notions that originate in your head are also theories, and the
'practical' results you achieve with them are so self evidently inferior
to what can demonstrably be achieved that even you should be questioning
them, and not at all surprised that nobody else gives you any credence
at all.

Richard.
Feb 3 '06 #20
VK

Richard Cornford wrote:
The javascript array has no potential to have multiple dimensions and so
no potential to be 'jagged'. Both concepts can be successfully
implemented/emulated with javascript but that can not be done with a
single javascript Array, and so the terms 'multi-dimensional' and
'jagged' are not applicable as characteristics of a javascript Array.


It's too late and I'm too tired to continue this discussion right now.
But I bookmark this statement till the next array question - where
you'll have an opportunity to answer it without using words "dimension"
or "jagged" or "pseudo-dimension" (because pseudo-dimension directly
leads to "jagged"). From my humble and very possibly wrong point of
view it will be funny.

Feb 3 '06 #21
VK said the following on 2/3/2006 6:57 AM:
Richard Cornford wrote:
The javascript array has no potential to have multiple dimensions and so
no potential to be 'jagged'. Both concepts can be successfully
implemented/emulated with javascript but that can not be done with a
single javascript Array, and so the terms 'multi-dimensional' and
'jagged' are not applicable as characteristics of a javascript Array.
It's too late and I'm too tired to continue this discussion right now.


Promise? To me, it's not a discussion, it is a one-sided statement from
Richard showing the flaws in what you are saying.
But I bookmark this statement till the next array question - where
you'll have an opportunity to answer it without using words "dimension"
or "jagged" or "pseudo-dimension" (because pseudo-dimension directly
leads to "jagged").
I can answer *any* question not directly related to mutil-dimensional
arrays without using any one of those three phrases, and in fact I
wouldn't even consider using any of those terms unless it was directly
related to the question.
From my humble and very possibly wrong point of view it will be funny.


To date, most of your points of view with regards to Array's has been
dead wrong. The funny part is watching you trying to defend that position.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 3 '06 #22
VK wrote:
Thomas 'PointedEars' Lahn wrote:
VK wrote:
> Leszek wrote:
>> Is it possible in javascript to operate on an array without knowing
>> how mamy elements it has?
>
> JavaScript array is Dynamic Sparse Jagged Array. That can be too much
> of adjectives for one time :-)
But I am sure you can invent more just to cover your lack of knowledge
and understanding of the basics.


JavaScript array is Dinamic, is Sparse and is Jagged.


Whatever this means to you.
[...]
<http://www.geocities.com/schools_ring/ArrayAndHash.html> is the only
one known (to me at least) resource there all three features along with
other information would be named and illustrated properly: [...]


That you do not understand the correct terms used in public specifications
and vendors' documentation does not mean that they are bad. That you do
not understand what was written before does not make your explanations,
based on your misconceptions, any better than it.

<URL:http://developer.mozilla.org/js/specs/ecma-262#a-15.4>
<URL:http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Literals#Array_Literals>
<URL:http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Predefined_Core_Objects: Array_Object>
<URL:http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array >
<URL:http://msdn.microsoft.com/library/en-us/script56/html/08e5f552-0797-4b48-8164-609582fc18c9.asp>
<URL:http://msdn.microsoft.com/library/en-us/jscript7/html/jsobjarray.asp>
PointedEars
Feb 3 '06 #23
VK wrote:
Ian Collins wrote:
I think the previous responses over looked the use of
for( var n in array ) {} as a method for iterating over an array.

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

function test( names )
{
for( var name in names )
{
// do something.
}
}

for-in loop has nothing to do with *array*, it's an iterator over
enumerable properties of object.


Strange comment - arrays are objects. For-in works fine provided you
deal with properties that aren't numbers.

Try this to understand the difference:

var arr = [1,2,3];
arr.foo = 'bar';

for (var i=0; i<arr.length; i++) {
alert(arr[i]);
}

for (var p in arr) {
alert(p);
}


I guess you are suggesting that if some of the properties aren't
numbers, you'll get erroneous results. But that can happen with a for
loop too and is catered for in the solutions offered above (typeof and
isNaN tests are obvious choices).

Ian's suggested method offers significant speed benefits *if* the array
length is large *and* the array is very sparse - otherwise, there is
little to recommend it.

Neither of the above conditions were suggested by the OP, but the point
is useful to understand.
--
Rob
Feb 3 '06 #24
RobG said the following on 2/3/2006 9:11 AM:
VK wrote:
Ian Collins wrote:
I think the previous responses over looked the use of
for( var n in array ) {} as a method for iterating over an array.
Could you show me a little example how to do this?
function test( names )
{
for( var name in names )
{
// do something.
}
}

for-in loop has nothing to do with *array*, it's an iterator over
enumerable properties of object.


Strange comment - arrays are objects. For-in works fine provided you
deal with properties that aren't numbers.


VK confuses the hell out of me sometimes, but I think he confuses
himself more. What I think he meant was that for-in is not limited to
arrays but can be used on any object.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 3 '06 #25
RobG wrote:
for-in loop has nothing to do with *array*, it's an iterator over
enumerable properties of object.


Strange comment - arrays are objects. For-in works fine provided you
deal with properties that aren't numbers.


.... and provided you aren't too choosy about the order in which you process
the array elements: the order of iteration produced by for..in is
undefined, and can suprise people who don't realise that.

If you don't believe me, try the following:

var a = ['a', 'b', 'c'];
a[4] = 'e'; a[3] = 'd';
for(var idx in a) {
alert(idx+"="+a[idx]);
};

The alerts in IE and Firefox go in the order 0,1,2,4,3 (although a
conforming ecmascript implementation could use any order it fancied).
Feb 3 '06 #26
Duncan Booth wrote:
RobG wrote:
for-in loop has nothing to do with *array*, it's an iterator over
enumerable properties of object.

Strange comment - arrays are objects. For-in works fine provided you
deal with properties that aren't numbers.


.... and provided you aren't too choosy about the order in which you process
the array elements: the order of iteration produced by for..in is
undefined, and can suprise people who don't realise that.

If you don't believe me, try the following:

var a = ['a', 'b', 'c'];
a[4] = 'e'; a[3] = 'd';
for(var idx in a) {
alert(idx+"="+a[idx]);
};

The alerts in IE and Firefox go in the order 0,1,2,4,3 (although a
conforming ecmascript implementation could use any order it fancied).


Note, too, that "idx" above is treated as a string, not an integer.

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
Feb 3 '06 #27
John W. Kennedy wrote:
Duncan Booth wrote:
[...]
var a = ['a', 'b', 'c'];
a[4] = 'e'; a[3] = 'd';
for(var idx in a) {
alert(idx+"="+a[idx]);
};

The alerts in IE and Firefox go in the order 0,1,2,4,3 (although a
conforming ecmascript implementation could use any order it fancied).


Note, too, that "idx" above is treated as a string, not an integer.


However, this does not matter here. All property names are strings. In
fact, any expression as property name is subject to ToString() conversion
on property access. See ECMAScript Ed. 3, 11.2.1 and 15.4.

This means that the property accesses a["3"] and a[3], and ({3: 33})["3"]
and ({3: 33})[3] are equivalent.
PointedEars
Feb 3 '06 #28
VK

Randy Webb wrote:
To me, it's not a discussion, it is a one-sided statement from
Richard showing the flaws in what you are saying.
And I'm showing the flaws in what he is saying while both are staying
away from Thomas'-like vocabulary. To me, it is a discussion. ;-)
I can answer *any* question not directly related to mutil-dimensional
arrays without using any one of those three phrases, and in fact I
wouldn't even consider using any of those terms unless it was directly
related to the question.
This loud statement is bookmarked too :-)
To date, most of your points of view with regards to Array's has been
dead wrong. The funny part is watching you trying to defend that position.


It was confirmed by many, including professional programmers and
programming specialists. As it brings them automatically to the
category of "people who knows no more or even less than VK does":- my
question would be what authority besides Richard Cornford would you
accept as an authority? I'm really open for requests: except a message
form the Lord and a wiki article. The first is out of my power, the
latter is too bi..y to use (it says whatever one wants - for at least
an hour).
So exept that?

Feb 3 '06 #29
Thomas 'PointedEars' Lahn wrote:
John W. Kennedy wrote:
Duncan Booth wrote:
[...]
var a = ['a', 'b', 'c'];
a[4] = 'e'; a[3] = 'd';
for(var idx in a) {
alert(idx+"="+a[idx]);
};

The alerts in IE and Firefox go in the order 0,1,2,4,3 (although a
conforming ecmascript implementation could use any order it fancied).

Note, too, that "idx" above is treated as a string, not an integer.


However, this does not matter here. All property names are strings. In
fact, any expression as property name is subject to ToString() conversion
on property access. See ECMAScript Ed. 3, 11.2.1 and 15.4.

This means that the property accesses a["3"] and a[3], and ({3: 33})["3"]
and ({3: 33})[3] are equivalent.


Yes, but it makes the semantics of "+" surprising.

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
Feb 3 '06 #30
On 2006-02-02, Leszek <le*******@poczta.onet.pl> wrote:
Hi.

Is it possible in javascript to operate on an array without knowing how mamy
elements it has?


No it is not because all arrays have a length property which tells you how
many elements they have :)

Bye.
Jasen
Feb 3 '06 #31
Richard Cornford wrote:
<snip>
The javascript array has no potential to have multiple
dimensions and so no potential to be 'jagged'. ...

<snip>

As it happens it has just occurred to me that the concept of a
multi-dimensional array can be implemented with a single javascript
Array:-

var a = [];

for(var c = 0;c < 10;++c){
a[c] = a;
}

- The result is a single array that emulates an array with infinite
dimensions. I.E. you can stick as many sets of square brackets and valid
array indexes after the array's Identifier as you want:-

var y = a[0][0][0][0][0][0][0][0][0][0] ... [0][0][0][0][0];

- and still get a valid result from the evaluation of the property
accessor. The resulting object is of course utterly useless as an array,
it will be broken by any attempt to store anything in it, and it is not
(and could not be) 'jagged'. But utterly useless as the result may be it
is one, and the only one, way that a single javascript array can appear
to be multi-dimensional.

Richard.
Feb 3 '06 #32
John W. Kennedy wrote:
Thomas 'PointedEars' Lahn wrote:
John W. Kennedy wrote:
Duncan Booth wrote:
[...]
var a = ['a', 'b', 'c'];
a[4] = 'e'; a[3] = 'd';
for(var idx in a) {
alert(idx+"="+a[idx]); ^^^^^^^ };

The alerts in IE and Firefox go in the order 0,1,2,4,3 (although a
conforming ecmascript implementation could use any order it fancied).
Note, too, that "idx" above is treated as a string, not an integer.

However, this does not matter here. All property names are strings. In
fact, any expression as property name is subject to ToString() conversion
on property access. See ECMAScript Ed. 3, 11.2.1 and 15.4.

This means that the property accesses a["3"] and a[3], and ({3: 33})["3"]
and ({3: 33})[3] are equivalent.


Yes, but it makes the semantics of "+" surprising.


I do not see your point, string concatenation always happens with the above
code, and nothing is attempted to be computed. Maybe you are referring to
the following solution for the OP's problem:

var
a = [1, 654, 2, 5, 489, 51, 3851, 681, 32, 5, 0],
sum = 0;

for (var idx in a)
{
sum += a[idx];
}

It also does not matter here whether `idx' refers to an integer (there are
no integers in ECMAScript implementations, all numeric values are IEEE-754
doubles), or to a string value, as it actually does. Note that it is _not_
the indexes that should be added but the array element's values they refer
to.
HTH

PointedEars
Feb 3 '06 #33
Jasen Betts wrote:
On 2006-02-02, Leszek <le*******@poczta.onet.pl> wrote:
Is it possible in javascript to operate on an array without knowing how
mamy elements it has?


No it is not because all arrays have a length property which tells you how
many elements they have :)


Should not that have rather been a "Yes it is because ..." answer? ;-)
PointedEars
Feb 3 '06 #34
VK

Richard Cornford wrote:
Richard Cornford wrote:
<snip>
The javascript array has no potential to have multiple
dimensions and so no potential to be 'jagged'. ...

<snip>

As it happens it has just occurred to me that the concept of a
multi-dimensional array can be implemented with a single javascript
Array:-

var a = [];

for(var c = 0;c < 10;++c){
a[c] = a;
}

- The result is a single array that emulates an array with infinite
dimensions. I.E. you can stick as many sets of square brackets and valid
array indexes after the array's Identifier as you want:-

var y = a[0][0][0][0][0][0][0][0][0][0] ... [0][0][0][0][0];


Richard, what's that? And how is it related with dimensions? It's a
single-dimensional array having 10 elements where each element value is
a reference to the containing array.

Feb 3 '06 #35
VK wrote:
Richard Cornford wrote:
Richard Cornford wrote:
<snip>
> The javascript array has no potential to have multiple
> dimensions and so no potential to be 'jagged'. ... <snip>

As it happens it has just occurred to me that the concept of a
multi-dimensional array can be implemented with a single
javascript Array:-

var a = [];

for(var c = 0;c < 10;++c){
a[c] = a;
}

- The result is a single array that emulates an array with
infinite dimensions. I.E. you can stick as many sets of square
brackets and valid array indexes after the array's Identifier
as you want:-

var y = a[0][0][0][0][0][0][0][0][0][0] ... [0][0][0][0][0];


Richard, what's that?


It is what is known as 'intellectual rigor' (look it up).
And how is it related with dimensions? It's a
single-dimensional array having 10 elements where each
element value is a reference to the containing array.


It is an array of arrays that only employs a single javascript array.

An emulation in javascript of what can be achieved with a
multi-dimensional array in languages that have such can only be done
with an array of arrays. Requiring an array of arrays implies that any
emulation of a multi-dimensional array cannot be done with a single
javascript Array object. I have demonstrated that there is a single case
where an array of arrays can be constructed and still only employ a
single javascript Array object.

Utterly useless as this one special case may be it would be dishonest to
deny its existence. Fortunately my deduction was that since an emulation
of what can be done with a 'jagged' array in languages that support such
can only be done with an array of arrays then 'jagged' cannot be an
appropriate term to apply to any single javascript array object, and so
'jaggedness' is not a quality of javascript Arrays. As the one
exceptional case where a single javascript Array object may appear to be
multi-dimensional in no way qualifies as 'jagged' that premise is not
altered by that observation.

Richard.
Feb 3 '06 #36
VK

Richard Cornford wrote:
var a = [];

for(var c = 0;c < 10;++c){
a[c] = a;
}
It is an array of arrays that only employs a single javascript array.


It is not: you have forgotten that in JavaScript arrays (as other
objects) are passed *by reference*. So you've created a rather
interesting (I have to admit it) circular structure where on each loop
you change the a[] array and add new reference on it into a[] itself.
But by the end you still have nothing but references to the same object
in all elements. This is why you cannot make any assignment in this
structure - it would be like to be a spectateur and the main "hero" on
funerals.
Same twist can be done with the associative array as well (with the
same useless outcome) so it is not anyhow related with the array
question.
An emulation in javascript of what can be achieved with a
multi-dimensional array in languages that have such can only be done
with an array of arrays. Requiring an array of arrays implies that any
emulation of a multi-dimensional array cannot be done with a single
javascript Array object. I have demonstrated that there is a single case
where an array of arrays can be constructed and still only employ a
single javascript Array object.


You are coming from the wrong assumption that multi-dimensional array
and jagged array are in XOR relations for any given language (so either
m-d or jagged but not both). It is not true: in some languages (say C#)
you can operate with both types. So even if you could create a real m-d
array in JavaScript it would not deny per se the jagged nature of the
Array as it is (thus as it's presented by default in the programming
environment).

I have a feeling that you just don't like the term "jagged" as some
low-class name, like it was with "hash". I could propose than another
as well official naming pair by calling m-d array "safe" array and
jagged array "unsafe" array. I'm not going to use it personally:
because m-d and jagged are more common and more "talking", but for this
thread that could be a compromise.

Feb 3 '06 #37
VK wrote:
Richard Cornford wrote:
>> var a = [];
>>
>> for(var c = 0;c < 10;++c){
>> a[c] = a;
>> } It is an array of arrays that only employs a single javascript
array.


It is not: you have forgotten that in JavaScript arrays (as
other objects) are passed *by reference*. So you've created
a rather interesting (I have to admit it) circular structure
where on each loop you change the a[] array and add new reference
on it into a[] itself. But by the end you still have nothing but
references to the same object in all elements.


It was you who introduced the expression 'array of arrays' into this
thread, if you don't want to consider an array of elements that have
values that are references to arrays as an array of arrays then you
should not have introduced the expression into this discussion in the
first place.
This is why you cannot make any assignment in
this structure - it would be like to be a spectateur
and the main "hero" on funerals.
It is not the fact that an array or arrays can only be an array of
references to arrays in javascript that precludes meaningful assignment
to array index properties in this structure. That is a consequence of
all of the references referring to the same array, and if they did not
all refer to the same array then this apparently multi-dimensional
structure would not be constructed of a single javascript Array and so
could not be considered as an exception to proposition that the term
multi-dimensional cannot be applied to a single javascript Array.
Same twist can be done with the associative array as well
(with the same useless outcome) so it is not anyhow related
with the array question.
The 'array question' we are dealing with here is whether the term
'jagged' can be applied as a characteristic of javascript Arrays. That
question has side-tracked through a consideration of whether the term
'multi-dimensional' can be applied as a characteristic of javascript
Arrays.

The original question is answered by pure logic because in javascript:-

IF ('jagged') THEN (NOT a single Array object)

- is a truth, and therefor:-

IF (a single Array object) THEN (NOT 'jagged')

- is also a truth. The singleness of any single javascript array
precludes jaggedness so jaggedness is not a characteristic of javascript
arrays (it can only be a characteristic of javascript structures that
would normally be constructed of multiple (at least 2) arrays).

On the other hand:-

IF (multi-dimensional) THEN (NOT a single Array object)

- is not a truth in javascript as a single javascript Array instance can
demonstrably form a structure that resembles the type of structure
needed to implement multi-dimensionalness sufficiently closely to be
regarded as multi-dimensional itself.

It is certainly not a good idea to characterise javascript arrays as
multi-dimensional, but that characterisation cannot be precluded upon
purely logical grounds in the way the characteristic 'jagged' can.
An emulation in javascript of what can be achieved with a
multi-dimensional array in languages that have such can
only be done with an array of arrays. Requiring an array
of arrays implies that any emulation of a multi-dimensional
array cannot be done with a single javascript Array object.
I have demonstrated that there is a single case where an
array of arrays can be constructed and still only employ a
single javascript Array object.


You are coming from the wrong assumption that multi-dimensional
array and jagged array are in XOR relations for any given
language (so either m-d or jagged but not both).


It is hard for me to say what misconceptions of English and logic have
led you to this wrong, irrelevant and insane conclusion. You really are
utterly out of your depth in any reasoned debate.
It is not true: in some languages (say C#) you can operate
with both types. So even if you could create a real m-d array
in JavaScript it would not deny per se the jagged nature of
the Array as it is (thus as it's presented by default in the
programming environment).
It should be so obvious that there is not need to state that for an
array jaggedness pre-supposes multi-dimensionality.
I have a feeling that you just don't like the term "jagged" ...

<snip>

You are wrong.

Richard.
Feb 4 '06 #38
VK wrote:
Richard Cornford wrote:
>> var a = [];
>>
>> for(var c = 0;c < 10;++c){
>> a[c] = a;
>> } It is an array of arrays that only employs a single javascript array.


It is not: you have forgotten that in JavaScript arrays (as other
objects) are passed *by reference*.


Nonsense.

First, it *is* an array of arrays that only employs a single Array (object).

Second, objects are not passed at all, they merely are created and exist
until they are garbage-collected when they are no longer referred.
References to objects are passed to functions by value, just as any other
value. But here no function call is involved, I wonder what this would
have to do with that (well, in fact I do not wonder really -- it is all
too clear that you have exactly no clue what you are talking about).
So you've created a rather interesting (I have to admit it) circular
structure where on each loop you change the a[] array and add new
reference on it into a[] itself. But by the end you still have nothing but
references to the same object in all elements.
Richard recognized that already (but of course you have either not read or
not understood his explanations), and that this is the only way a
J(ava)Script/ECMAScript array can be really multi-dimensional. Which was
the whole point of his example.
This is why you cannot make any assignment in this structure - it would
be like to be a spectateur and the main "hero" on funerals.

^^^^^^^^^^ Should this be French for "spectator"?

More nonsense. An assignment is entirely possible everywhere within this
structure; the reference to the own Array object would be replaced with the
assigned value. The resulting array would be an array where the element
with the same index as the index of the last property access is replaced
with that value. For example, with

a[1][2][3][0] = 42;

/*
the assignment is evaluated as follows:

0. a[1][2][3][0] = 42;
1. a[2][3][0] = 42; // a[1] === a
2. a[3][0] = 42; // a[2] === a
3. a[0] = 42; // a[3] === a

While

42,,,,,,,,,

is displayed with
*/

window.alert(a);

/*
the real, infinitely recursive (`...'), and therefore programmatically
not displayable data structure is

[
42,
[42, [42, [42, [42, [42, [42, ...], ...], ...], ...], ...], ...]
[...],
[...],
[...],
[...],
[...],
[...],
[...],
[...]
]

(where `[...]' is just a means to say "Array object", not "new Array
object"), as can be showed with
*/

window.alert(a[1]); // a[1] === a[2] === ... === a[9] === a
window.alert(a[1][0]); // a[1][0] === a[0] === 42
window.alert(a[1][1]); // a[1][1] === a[1] === a
window.alert(a[1][1][0]); // a[1][1][0] === a[1][0] === a[0] === 42
window.alert(a[1][2][0]); // a[1][2][0] === a[2][0] === a[0] === 42
// ...
window.alert(a[2]); // a[2] === a[1] === ... === a[9] === a
window.alert(a[2][0]); // a[2][0] === a[0] === 42
window.alert(a[2][1][0]); // a[2][1][0] === a[1][0] === a[0] === 42
// ...
window.alert(a[2][2]); // a[2][2] === a[2] === a
window.alert(a[2][2][0]); // a[2][2][0] === a[2][0] === a[0] === 42

// and so on.
PointedEars
Feb 4 '06 #39
VK
Who's interested in what I'm answering to please read the whole thread
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/046263f60dbb73f0/f3fe79c21622df04#f3fe79c21622df04>
Gentlemen,

That's getting really dangerous for you: in order to prove one wrong
point (that JavaScript Array is not jagged) you had to intriduce a
bounch of new wrong points plus you had to disavow a lot of you
previous statements. It's dangerous because it's a sure way to
transform a discussion into a casuistical match where the only task is
to negate the very last statement of your opponent without relation
with the topic and the previous statements.

In your attempt to dismiss VK you even stated that JavaScript Array is
a whole separate data structure having much more difference from other
structures (like generic Object) than simply length autocounter. At any
other time it would fill my heart with joy, but not now because I see
that it is not an expression of the real believe I'm seeking from you
but a momentary side-effect of your excitement :-)

Questions to be answered:
1) What is multi-dimensional array
2) What is jagged array
3) What is safe and unsafe array and their relations with m-d and j
arrays
4) What is the nature of JavaScript Array

I know the exact answers on each and every of these questions after one
year of careful studies. I still want to give each question not by my
stupid mouth but by some *reputable* *printed* source. It will take
some time (within a week I guess) as I'm mostly on my JSONet project at
my spare time. But I feel it is necessary to move out the discussion
out of the personal opinions into a discussion over some publically
established categories.

I guess it will be more productive.

Feb 4 '06 #40
Thomas 'PointedEars' Lahn <Po*********@web.de> writes:
Jasen Betts wrote:
On 2006-02-02, Leszek <le*******@poczta.onet.pl> wrote:
Is it possible in javascript to operate on an array without knowing how
mamy elements it has?


No it is not because all arrays have a length property which tells you how
many elements they have :)


Should not that have rather been a "Yes it is because ..." answer? ;-)


I guess the joke could be that it's not possible to operate on an
array without know how many elements it has, because you *do* know how
many elements it has.

(and then we are back at the discussion about whether a unassigned
index less than length counts as an element or not :)
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Feb 4 '06 #41
"VK" <sc**********@yahoo.com> writes:
Questions to be answered:
1) What is multi-dimensional array
It's a vague term. Let's use the C definition, where it is a
rectangular structure of elements, that requires more than one index
to look up the elements. The structure is "rectangular" in that the
range of valid indices on the different index-axes are independent of
eachother.
2) What is jagged array
I must guess here, because I haven't heard it before. I'm guessing
that it is a structure where you need more than one index to look up
elements, but where the range of valid values on the secondary (and
later) æs depend on the previous ones.

This is what you get with an array of array references in most
langauges, including C (where references are called pointers), Java
and Javascript.
3) What is safe and unsafe array and their relations with m-d and j
arrays
Have no idea. What are safe and unsafe arrays?
4) What is the nature of JavaScript Array


Ah, the old question.

A Javascript array is a special Javascript host object, possibly
created using the Array constructor function, where certain property
names are considered special "array indices", and which has a length
property that is always at least one larger than the largest "array
index" property that the object contains.

This allows you to treat the array object as a sparse array in other
languages, while still using all object properties on it as well.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Feb 4 '06 #42
Lasse Reichstein Nielsen wrote:
"VK" <sc**********@yahoo.com> writes:
4) What is the nature of JavaScript Array


Ah, the old question.

A Javascript array is a special Javascript host object, [...]


It is a native object, _not_ a host object.
PointedEars
Feb 4 '06 #43
VK wrote:
Who's interested in what I'm answering to please read the
whole thread
http://groups.google.com/...
What is the point of referring people who are reading this thread to
this thread?
Gentlemen,

That's getting really dangerous for you:
Dangerous? The only danger is of wasting ones time as your intellectual
arsenal is so deficient that you may never see that the point under
discussion was resolved at the time Randy posted yesterday.
in order to prove one wrong point (that JavaScript Array is
not jagged)
Not only is that not one wrong point, it is a point that is so not wrong
that it can be proven logically. The only potential vulnerability of
that proof being someone being able to demonstrate a structure
exhibiting 'jaggedness' created with a single javascript Array instance
(and that looks like an imposibility).
you had to intriduce a bounch of new wrong points
State one. (Or if it is a bunch state all of them, though attempting to
state one will be sufficient to show that no such 'new wrong points'
have been introduced.).

In fact the ability to assert that:-

IF ('jagged') THEN (NOT a single Array object)

- is a truth in javascript is all that is necessary to prove that the
term 'jagged' cannot characterise a javascript Array (only, possibly,
some javascript structures).
plus you had to disavow a lot of you previous statements.
State one. (Or if it is a lot state all of them, though attempting to
state one will be sufficient to show that no previous statements have
been disavowed).
It's dangerous because it's a sure way to transform a discussion
into a casuistical match where the only task is to negate the
very last statement of your opponent without relation
with the topic and the previous statements.
Your poor attempt to apply my "own thesis" to C++ and Java arrays
demonstrated the only likely source of flawed reasoning in this
discussion.
In your attempt to dismiss VK you even stated that JavaScript
Array is a whole separate data structure having much more
difference from other structures (like generic Object) than
simply length autocounter.
Where? If that has been said you should be able to quote the specific
statment.
At any other time it would fill my heart with joy, but not
now because I see that it is not an expression of the real
believe I'm seeking from you but a momentary side-effect of your
excitement :-)
More likely you perception of such a statement where none exists is
merely an artefact of your wider misconceptions, incomprehension of
English and general irrationality.
Questions to be answered:
1) What is multi-dimensional array
Something that does not exist in javascript, but can be emulation with a
structure (most directly with an array of arrays).
2) What is jagged array
Something that does not exist in javascript, but can be emulation with a
structure (most directly with an array of arrays).
3) What is safe and unsafe array and their relations with
m-d and j arrays
Irrelevant notions that popped out of your mind for no apparent reason,
and with no real purpose.
4) What is the nature of JavaScript Array
Whatever else the nature of a javascript Array is it is certainly not in
its nature to be 'jagged'.
I know the exact answers on each and every of these
questions after one year of careful studies.
LOL. When you announced last week that one month of studying Mozilla
browsers had taken you from a position of (presumably) not knowing
whether it supports the document.styleSheets collection to concluding
that it does not you made it obvious that for you study actually
increases the falseness of your beliefs. If a month's application of
your perverse mental processes can do that I hate to imagine how wrong
you could be after a year.

It should be obvious that you cannot be the only person studying this
subject and so when you are the _only_ person studying the subject who
ends up believing what your believe about it (and you cannot convince
anyone with any familiarity with the subject that you are correct) it
should be equally obvious that your you are applying a flawed process to
your studies.
I still want to give each question not by my stupid mouth but
by some *reputable* *printed* source.
Very few sources of information about javascript are both reputable and
printed.
It will take some time (within a week I guess) as I'm
mostly on my JSONet project at my spare time.
I won't be holding my breath. So far whenever you have promised that you
would post some response at a more distant future date you have not done
so (and I was looking forward to you attempting to defend your
misrepresentation of Ockham's razor, but it has not materialised yet).
But I feel it is necessary to move out the discussion out
of the personal opinions into a discussion over some
publically established categories.
The only unsustainable personal opinions being post to this thread have
been posted by you, so if you want to keep the discussion within the
area of reasoned discussion that is entirely at your discretion (though
potentially not within your power).

You should remember that we are on Usenet here. If I were posting what
was perceived as irrational nonsense there would be people posting
follow-ups telling me so. That doesn't appear to be happening, so what
is the best explanation for that?
I guess it will be more productive.


What I have seen of your "JSONet project" so far falls into the category
of "bizarre and obtuse" so no, it probably won't be more productive
(unless you would otherwise spend the time 'studying'). On the other
hand it probably won't be less productive for you either.

Richard.
Feb 4 '06 #44
Jasen Betts said the following on 2/3/2006 4:48 AM:
On 2006-02-02, Leszek <le*******@poczta.onet.pl> wrote:
Hi.

Is it possible in javascript to operate on an array without knowing how mamy
elements it has?


No it is not because all arrays have a length property which tells you how
many elements they have :)


You sure about that?

<script type="text/javascript">
var myArray = new Array()
myArray['myArrayElement'] = 'something'
alert(myArray.length)
</script>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 4 '06 #45
VK said the following on 2/3/2006 1:14 PM:
Randy Webb wrote:
To me, it's not a discussion, it is a one-sided statement from
Richard showing the flaws in what you are saying.
And I'm showing the flaws in what he is saying while both are staying
away from Thomas'-like vocabulary. To me, it is a discussion. ;-)


They aren't flaws though VK. And staying away from Thomas'-like
vocabulary is always admirable.
I can answer *any* question not directly related to mutil-dimensional
arrays without using any one of those three phrases, and in fact I
wouldn't even consider using any of those terms unless it was directly
related to the question.


This loud statement is bookmarked too :-)


With regards to Javascript, bookmark it. As of this date, the script
engines on the web do not support, or even know of, a jagged or
multi-dimensional array. Nor do they support a *true* hash array.
To date, most of your points of view with regards to Array's has been
dead wrong. The funny part is watching you trying to defend that position.


It was confirmed by many, including professional programmers and
programming specialists.


They have to be JS programmers or JS Specialists as JS is totally
different than any other programming language out there simply because
of the unknown runtime environment.
As it brings them automatically to the category of "people who knows no more or even less than VK does":-

Think about what you wrote and anybody falls into the category of
knowing more or less than anybody else does.
my question would be what authority besides Richard Cornford would you
accept as an authority?
You are assuming, incorrectly, that I accept Richard as "an authority".
I have had my share of disagreements with Richard as well as other
people in this group. I trust no code until I test it myself, even
Richard's.

But, if I had to choose one person in this group to be "an authority",
it would be - hands down - Martin Honnen. I do not test Martin's code to
see if it works, I test it to tinker with it and learn other things.

Martin reminds of the old TV Commercial in the US. When Martin writes,
people listen.
I'm really open for requests: except a message form the Lord and
a wiki article. The first is out of my power, the latter is too
bi..y to use (it says whatever one wants - for at least an hour).
Wiki's are useless.
So exept that?


How about something for you to ponder?

Create a multi-dimensional array in JS where no element in that array is
an array.

If JS truly supports multi-dimensional arrays then you should have no
problem creating one for me without making any element in it an array.
And not even Richards example meets that requirement.

Let me know when you figure out that there is no multi-dimensional array
in JS.

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

Randy Webb wrote:
Let me know when you figure out that there is no multi-dimensional array
in JS.


The whole branch of this thread was that JavaScript array is *not*
multi-dimensional, they are *jagged*. These are two different
categories, and I continuosly stated that JavaScript array is jagged
(see my very first post), not multi-dimensional.

- A is true
- OK, then come back when you understand that A is true

? Who's out of loop here? :-0

I repeat my very first statement: "JavaScript Array is dynamic, jagged,
sparse"

I do not require that everyone in this group will understand this
definition as it requires rather good and specific programming
knowledge. But the fact if some term is not known to me doesn't mean
that the term is wrong or doesn't have sense. It just means that I
don't know something as well as I would like to, is not it?

<quote>
We are using the term "jagged array" to describe a
multi-dimensional array that is
not necessarily rectangular. A two-dimensional "jagged array" can
be thought of as
a vector, each element of which is a vector containing an arbitrary
number of objects.

[] > [] [] [] []
[] > [] [] []
[] > []
[] > [] [] [] []
</quote>

<quote>
The jagged array is basically an array of arrays. So, you one array
could have a length/size of 5 while the next has a size of 3 and the
next 2, and so on. You see the "jagged" part of it? The three would
look a little like this:
1, 2, 3, 4, 5
6, 7, 8
9, 10
Now, you can see that a jagged array can have arrays of different
lengths but in a multi-dimensional array, it is always a perfect
rectangle/cube, no matter what.
</quote>

These are quotes from works published on MIT.edu but I do *not* want to
place them as official references until some more answers I'm waiting
for.

It's just to explain again what I (and real programmers where I'm not
part of) do mean by saying "jagged array". It is cristal clear to
anyone why JavaScript array is jagged and no one ever tried to dismiss
it until this very thread. I'm not sure what your problem is, guys, but
I'm still willing to help, this is why I will bring more 3rd party
explanations and samples later as promised.

Feb 4 '06 #47
JRS: In article <25*****************@clunker.homenet>, dated Fri, 3 Feb
2006 09:48:55 remote, seen in news:comp.lang.javascript, Jasen Betts
<ja***@free.net.nz> posted :
On 2006-02-02, Leszek <le*******@poczta.onet.pl> wrote:

Is it possible in javascript to operate on an array without knowing how mamy
elements it has?


No it is not because all arrays have a length property which tells you how
many elements they have :)


But consider the values of L and N after executing

var A = []
A[99999] = 9
L = A.length // 100000
N = 0
for (J in A) N++ // 1

The validity of the *last* of those statements implies that the answer
to the question is "Yes".

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Feb 4 '06 #48
VK

Dr John Stockton wrote:
var A = []
A[99999] = 9
L = A.length // 100000
N = 0
for (J in A) N++ // 1

The validity of the *last* of those statements implies that the answer
to the question is "Yes".


"Yes" if you are using Array as Array and do not use it as hashtable
*and* as array *at the same time*. JavaScript is flexible enough for
this (and many more tricks), but they are usable only with a good
understanding of underlaying machanics:- otherwise it's a call for
troubles.

<http://www.geocities.com/schools_ring/ArrayAndHash.html>
Section "Array as hash" explains it in details.
P.S.
var A = new Function();
A[0] = 1;
A[9999] = 2;
for (var p in A) {alert(p);}

You can do a lot of things in javascript:- but not everything one can
do one *should* do, especially if the core matter is not clearly
understood.

Feb 4 '06 #49
VK said the following on 2/4/2006 3:18 PM:
Randy Webb wrote:
Let me know when you figure out that there is no multi-dimensional array
in JS.
The whole branch of this thread was that JavaScript array is *not*
multi-dimensional, they are *jagged*. These are two different
categories, and I continuosly stated that JavaScript array is jagged
(see my very first post), not multi-dimensional.


You need to re-look at the sub-thread that this is in. It starts with
Richard replying to you and you replying back about being late and
tired. Read from that point on. I said I could discuss arrays, and
explain them, without referring to "jagged", "multi-dimensional" and a
"hash array". Unless it was related to the question. And the only time I
will ever use those three terms in relation to JS arrays is to say "JS
Arrays do not possess those qualities" because they don't.
- A is true
- OK, then come back when you understand that A is true

? Who's out of loop here? :-0

I repeat my very first statement: "JavaScript Array is dynamic, jagged,
sparse"

I do not require that everyone in this group will understand this
definition as it requires rather good and specific programming
knowledge. But the fact if some term is not known to me doesn't mean
that the term is wrong or doesn't have sense. It just means that I
don't know something as well as I would like to, is not it?

<quote>
We are using the term "jagged array" to describe a
multi-dimensional array that is
not necessarily rectangular. A two-dimensional "jagged array" can
be thought of as
a vector, each element of which is a vector containing an arbitrary
number of objects.

[] > [] [] [] []
[] > [] [] []
[] > []
[] > [] [] [] []
</quote>
Read that first line. In order for an array to be "jagged" then it has
to be multi-dimensional according to your own quote. Since you admitted
that JS doesn't have multi-dimensional arrays then how can it have a
"jagged" array? It can't because in order for an array to be jagged it
has to be multi-dimensional.

<quote>
The jagged array is basically an array of arrays. So, you one array
could have a length/size of 5 while the next has a size of 3 and the
next 2, and so on. You see the "jagged" part of it? The three would
look a little like this:
1, 2, 3, 4, 5
6, 7, 8
9, 10
Now, you can see that a jagged array can have arrays of different
lengths but in a multi-dimensional array, it is always a perfect
rectangle/cube, no matter what.
</quote>

These are quotes from works published on MIT.edu but I do *not* want to
place them as official references until some more answers I'm waiting
for.
Do you actually trust your own quotes when they contradict one another?

First quote:
We are using the term "jagged array" to describe a
multi-dimensional array that is not necessarily rectangular.
Second quote:
The jagged array is basically an array of arrays.
Which is it? A multi-dimensional array or an array of arrays? JS can
have the second, it can't have the first.

If the people at MIT can't even figure out what they mean without
contradicting themselves, I will have to remember to stay away from them.
It's just to explain again what I (and real programmers where I'm not
part of) do mean by saying "jagged array".
If "real programmers" don't know the difference between a jagged array,
multi-dimensional array and an array of arrays, then please move me to
the amateur column because I don't want to be associated with them.

It is cristal clear to anyone why JavaScript array is jagged
No, it is crystal clear to anyone who understands JS that JS does not
possess a jagged array.
and no one ever tried to dismiss it until this very thread.
Probably because this is the first time anybody tried to improperly
apply the term "jagged" to a JS array.
I'm not sure what your problem is, guys, but I'm still willing to
help, this is why I will bring more 3rd party explanations and samples
later as promised.


The major problem is when someone says something that is not true and it
goes uncorrected then it leads to more questions down the road and it is
an effort to correct that incorrectness as early as possible.

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

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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.