Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  146] [ 1]  / answers: 1 / hits: 92474  / 11 Years ago, thu, february 6, 2014, 12:00:00

I am having a heck of a time trying to figure out how to create a multidimensional array in jQuery.



I instantiate the array outside of the loop.



 <script>
var myArray = [];
</script>


Inside of my loop I want to add the array elements.



 i = 0
[loop start]
<script>
myArray[i][$row[sku]] = $row[qty]; // sku might be repeated will this cause an issue? You will see in the error below 295518 is repeated...
<script>
[loop end]


In my source code it looks like this:



 <script>
myArray[ 1 ][ 295518 ] = 122;
</script>


Then I run this at the end outside the loop...



 <script>
console.log( myArray );
</script>


I get this error in the console:



Uncaught TypeError: Cannot set property '295518' of undefined 
Uncaught TypeError: Cannot set property '70252' of undefined
Uncaught TypeError: Cannot set property '295518' of undefined


What I am doing wrong in setting up this array? Thanks!


More From » php

 Answers
5

you can do so:



var a = [];
a[0] = [1,2,3];
a[1] = [4,5,6];

a[1][1] it is 5

[#72693] Tuesday, February 4, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
simone

Total Points: 558
Total Questions: 96
Total Answers: 99

Location: British Indian Ocean Territory
Member since Tue, Feb 22, 2022
2 Years ago
;