Hi I am trying to print out the first element and the element attached to that element in an array. I am getting ‘helloh’ in firefox and ‘helloundefined’ in IE. Does anyone know why this isn’t working.
Here is a jsfiddle.. http://jsfiddle.net/ZtuAu/
<script language=javascript>
var test = new Array();
test[0] = new Array();
test[0] = "hello";
test[0][0] = "world";
document.write(test[0] + test[0][0]);
</script>
You have an array
If you want to insert an item into it, use
pushBecause you want the array to update its length property etc.
So, you do this:
You’re assigning the same thing twice, so naturally, only the second assignment holds. So we have
Then, in FireFox, you can use
[]to access any character of the stringApparently, in IE you cannot do that, so you get
undefined.