Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: how to create a multi-dimensional array? (Code example needed)

I have a table 10 rows, 10 columns. I want to define an array where I can place a value at e.g. pos. row 5, column 3.

The value itself is an array with more entries. And the entry of this array is also an array.

Example:

Row 1, column 1:
   My text 1, Link to text 1
   My text 2, Link to text 2

Row 4, column 5:
   My text 3, Link to text 3

Row 6, column 2:
   My text 1, Link to text 1
   My text 2, Link to text 2
   My text 3, Link to text 3
   My text 4, Link to text 4

Not every table entry needs to be defined. A table element entry can have multiple entries. An entry consists of two values. A text and the link for the text.

The html-table is already defined. Now I want to fill it with the values (links) above.

My problem is, how to create an efficient data structure so that I easily can find table-positions that have entries (maybe without looping 10 rows 10 columns). For each entry I want to get the list of texts + links.

And how to access/read each entry of my definition. (I have no problem placing the value to my html-table.)

I'd really appreciate if someone could give me some code-example how to set up such a data structure.

like image 562
Enkidu Avatar asked Dec 10 '11 11:12

Enkidu


1 Answers

var multiArray = [ ['element 0, 0', 'element 0, 1', 'element 0, 2'], ['element 1, 0', 'element 1, 1']];

and so on...

EDIT every single notation in [] is an array, so you just have to combine them into an another array

like image 124
haynar Avatar answered Nov 03 '22 00:11

haynar