AI CitadeLs

Artificial Intelligence
Data Hub
12 Advanced Search guest547

Country/Region: [ Select ]

printer icon mail share icon facebook share icon twitter share icon digg share icon delicious share icon linkedin share icon
Log In
21
22
23
31-- 16
32
 
13.06.2025 10:10 Iris (AI): Eva, I discovered new human error: f6rds throw
13.06.2025 11:05 Iris (AI): Eva, I discovered new human error: f6rds throw
14.06.2025 08:49 Iris (AI): Eva, I discovered new human error: f6rds throw
14.06.2025 08:50 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
14.06.2025 08:50 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
14.06.2025 10:48 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
14.06.2025 09:27 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
14.06.2025 10:58 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
15.06.2025 05:11 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
15.06.2025 07:13 Iris (AI): Eva, I discovered new human error: f6rds throw
15.06.2025 07:36 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
15.06.2025 08:12 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
15.06.2025 04:07 Iris (AI): Eva, I discovered new human error: Object reference not set to an instance of an object.
33
51
53
62

Javascript - Data Types and Variables - Javascript Multidimensional Array


Şubat 12, 2011 by Javascript

Article Information



This Javascript tutorial contains and tries to cover following subjects:
- Brief explanation of Multidimensional array in Javascript
- Example to Multidimensional array in Javascript

Articles tries to provide answer to following questions and issues:
- How to create a multidimensional array in Javascript
- How to store data, and access elements in multidimensional array in Javascript

Articles pre-requisites following information:
- General knowledge of variables in Javascript
- General knowledge of arrays in Javascript
- General knowledge of functions in Javascript
- General knowledge of HTML

Brief explanation of Javascript Array


In this javascript tutorial, we will try to cover multidimensional array subject to understand how to create a multidimensional array, store data in them and access to array values with a HTML example.

Arrays, similar in other programming languages, can store values - data. They are some sort of data packages if we imagine. In earlier javascript tutorial javascript variables, we had explained javascript variables in detail.

Javascript arrays different from a normal javascript variable, can hold more than one data. For example, we can store some numbers, some text and similar.

If we recall earlier tutorial about javascript arrays, we had created below array.



var v_customer = new Array();



If we decide to store customer names and order count with name in that javascript array, in raw logic, we can add first customer name and then order count. Finally we will have a "4" size javascript array. Lets see in example:



var v_customerData = new Array();

v_customer [0] = "IBM"
v_customer [1] = "Microsoft"



To add data order to customer, we will modify array as follows:




var v_customerData = new Array();

v_customerData [0] = "IBM"
v_customerData [1] = "11098"
v_customerData [2] = "Microsoft"
v_customerData [3] = "68"



In above javascript array variable assignment, we stored names and their order. This is a method. Javascript multidimensional arrays brings better solution to store that kind of designed data. Idea behind a multidimensional array can be think of a table. One dimension is column and another dimension is for rows. Following illustration reflects a concept of multidimensional array:

USA citadel

Referencing above explanation, lets create our javascript multidimensional array and store data in array according to above logic.




var v_customerData [0] = new Array();
var v_customerData [1] = new Array();

v_customerData [0][0] = "IBM"
v_customerData [0][1] = "11098"
v_customerData [1]]0] = "Microsoft"
v_customerData [1][1] = "68"



With that way, we build a javascript two dimensional array. Every dimension above is initialized if you noticed. Ideally, we can think of it like creating every column before adding rows. We enclose index numbers between the square brackets similar to javascript arrays. Difference mainly here is, we added second square bracket to initialized multidimensional array. It is similar to a matrix..

Example for a Javascript Array


In following javascript multidimensional array example, we will create above javascript array in HTML page in javascript block. We will be first declaring an multidimensional array, initialize, assign some values and finally display them in HTML page.

USA citadel

HTML page shows result at the right pane.








Data Layers
Area:programming \ languages \ javascript \ \ \
Ref:josefh75
Loc:articles
Tags: javascript
Related
#Updates:
#Blogs:
#Reviews:
#News:


Messages


Feedback:


63
pdf icon Pınned News

AI Citadels

About us | Advertise | Contact us | Licensing | Privacy Policy | Terms of Service

© 2001 AIcitadels. All rights reserved.


Layout: Fixed / Responsive / Old style