My Pet Programmer wrote on 20 dec 2007 in comp.lang.javascript:
They don't have any properties. Multidimensional arrays in js don't
work like the good server side ones do (I'm php).
Multidimensional arrays in javascript do not exist!
You can define an array element a new array,
but that does not influence other elements in their behavour !!!
Javascript can be used clientside, serverside, and in a meriad of
other ways. so the contradiction of serverside and javascript does
not exist.
You are not php, I met php several times,
she did not look like you in the least.
You need to init each element of the second dimension before it can
be used. I usually build the second dim and tack in onto the first.
A second dim in Javascript, what is that?
Matrices and cubes have actually given me quite a bit of trouble
this week.
I am sorry to hear that.
var arrayName = new Array(); // first dim done
arrayName = 3; // valid
arrayName[j]; //invalid
Yes, logically, my dear php:
1 you just defined arrayName as having the numerical value of 3,
and then you expect it to be an array in itself?
2 arrays are not statements, usually.
Honestly, from the server side, I always use JSON formats. SO much
easier.
"from the server side"?
Oh yes, you profess to BE serverside.
Whose? Kevin's?
[Please do not toppost on usenet]
arrayName =
[
{"key1" :
[ { "Key2" :
["alpha_val":1]}
]
]
~A!
Kevin took the time to say:
Help!
Why are none of these valid?
var arrayName = new Array();
This is valid
arrayName['key1']['key2'] = new Array('alpha_val', 1);
You did not define the element to be an array!
Even so arrays are keyed by numbers.
You are using an object.
Arrays are objects, and objects can have properties:
look:
<script type='text/javascript'>
var a = []; // define an array;
a['seven'] = 7;
alert( a.length ); // the array is still empty of elements
alert( a['seven'] ); // see, no hands mam! the object has a
property
arrayName['key1']['key2'] = ['alpha_val', 1];
I believe you cannot do that with an object,
having a property have a property,
unless the first property is defined as an object.
<script type='text/javascript'>
var a = {}; // define an object
a['key1'] = {}; // define one of it's properties as an object
a['key1']['key2'] = 8;
alert(a['key1']['key2']); // see, no hands again, mam!
</script>
you could do this:
<script type='text/javascript'>
var a = []; // define an array-object
a['key1'] = []; // define a property as an array-object
a['key1']['key2'] = 8;
alert(a['key1']['key2']);
</script>
but here the array was used as an object,
the array behavour was not used at all.
I'm creating/writing the array on the server side from Perl,
With serverside javascript code, from perl? please explain.
but I keep getting a javascript error message saying
"arrayName.key1 has no properties."
How do you know it was javascript,
or do you get a clientside mesage?
I'm too bald to keep pulling my hair out...
Too ba[l]d.