473,898 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 17052
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 multidimensiona l 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.styleS heets -, 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

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

Similar topics

12
55586
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 also removed) So far I have (val is value, ar is array, returns new array):
13
2540
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
6544
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 the object references. However, I just realized that indices may only be referenced by strings.
47
5134
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 are not at all. If you are doing *array", then you have to use only integer values for array index, as it was since ALGOL.
22
4671
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 month I had enough of extra proof that the cat doesn't hount mice anymore in more and more situations. And the surrent sicretisme among array and hash is the base for it. I summarized all points in this article:...
2
5250
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 down to a very simple test case which can be cut-n-pasted into a .html file and viewed in a browser: ============================================================================
21
3240
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 column. Once the array elements are split, what is the best way to sort them? Thank you. //populate data object with data from xml file. //Data is a comma delimited list of values var jsData = new Array(); jsData = {lib: "#field...
30
2968
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
2521
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 the array is an object itself but what is this syntax of the consecutive double quotes inside the brackets ?
0
11265
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10858
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8036
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5882
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4296
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3307
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.