Mảng đa chiều không được cung cấp trực tiếp trong JavaScript. Nếu chúng ta muốn sử dụng bất cứ thứ gì hoạt động như một mảng đa chiều thì chúng ta cần tạo một mảng đa chiều bằng cách sử dụng một mảng một chiều khác. Vì vậy, các mảng đa chiều trong JavaScript được gọi là các mảng bên trong một mảng khác. Chúng ta cần đặt một số mảng bên trong một mảng, sau đó tổng số điều hoạt động giống như một mảng đa chiều. Mảng, trong đó các mảng khác sẽ chèn, mảng đó được sử dụng làm mảng đa chiều trong mã của chúng tôi. Để xác định một mảng đa chiều, nó giống hệt như xác định một mảng một chiều bình thường.
Mảng một chiều:
var arr = []; // Empty 1D array var arr1 = ["A", "B", "C", "D"] // 1D array contains some alphabets var arr1 = [1, 2, 3, 4, 5] // 1D array contains some digits
Mảng đa chiều đa chiều:
- Phương pháp 1: ________ 1
1st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
Ở đây ARR1, ARR2, ARR5 là một số mảng 1D bên trong mảng lương.
- Phương pháp 2: ________ 2
var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
Ở đây, mảng tiền lương hoạt động giống như một mảng đa chiều. Ký hiệu này được gọi là nghĩa đen.
Truy cập phần tử của mảng tiền lương:
- Để truy cập phần tử mảng, chúng tôi cần một ký hiệu dựa trên chỉ mục đơn giản
- Đối với nhiều lần lặp, chúng ta cần sử dụng vòng lặp để truy cập các yếu tố, ________ 4
Thêm các phần tử trong mảng đa chiều: Thêm các phần tử vào các mảng đa chiều có thể đạt được theo hai cách trong mảng bên trong hoặc mảng bên ngoài. Mảng bên trong có thể được thực hiện theo hai cách khác nhau. Adding elements in multi-dimensional arrays can be achieved in two ways in inner array or outer array. The inner array can be done in two different ways.
- Thêm các phần tử vào mảng bên trong:
- Chúng ta có thể sử dụng ký hiệu khung vuông đơn giản để thêm các phần tử vào mảng đa chiều .________ 5
- Chúng ta có thể sử dụng phương thức push [] để thêm các phần tử vào mảng .________ 6push[] method to add elements in the array.
salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
- Thêm các phần tử vào mảng bên ngoài: Nó tương tự như các phương thức trước đó .________ 7 It is much similar to previous methods.
salary.push[["MNO", 29, 33300]]; // This row added after the last row in the "salary" array
Loại bỏ các phần tử trong mảng đa chiều: chúng ta có thể sử dụng các phương thức pop [] để loại bỏ các phần tử khỏi phần bên trong và cũng sử dụng phương thức pop [] để loại bỏ toàn bộ mảng bên trong. We can use pop[] methods to remove elements from inner-arrays, and also use pop[] method for removing a entire inner array.
// Remove last element from 4th sub-array // That is 28000 indexing starts from 0 salary[3].pop[]; // Removes last sub-array // That is "["EFG", 31, 28000]" salary.pop[];
- Ví dụ 1:
1st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
51st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
61st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
71st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
81st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
91st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
1var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
22231st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
5var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
6var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
71st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
9var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
2221st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
3var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
2221st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
7// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
8// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
91st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
1// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
2// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
3// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
4// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
6// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
7Output:
ABC, 24, 18000 EFG, 30, 30000 IJK, 28, 41000 EFG, 31, 28000 EFG, 29, 35000
- Ví dụ 2:
1st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
51st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
0salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
21st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
8salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
4salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
2salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
8salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
6salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
2salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
2salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
6salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
7// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
8// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
91st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
1// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
2// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
3// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
4// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
6salary.push[["MNO", 29, 33300]]; // This row added after the last row in the "salary" array
7Output:
ABC, 24, 18000 EFG, 30, 30000 IJK, 28, 41000 EFG, 31, 28000 EFG, 29, 35000
- Ví dụ 2:
1st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
51st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
0salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
21st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
8salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
4salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
2salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
8salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
6salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
2salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
2salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
6salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
7Ví dụ 3:
ABC, 24, 18000 EFG, 30, 30000 IJK, 28, 41000 EFG, 31, 28000 EFG, 29, 35000
8ABC, 24, 18000 EFG, 30, 30000 IJK, 28, 41000 EFG, 31, 28000 EFG, 29, 35000
91st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
00// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
4// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5salary.push[["MNO", 29, 33300]]; // This row added after the last row in the "salary" array
7Output:
1st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
1 ABC, 24, 18000 EFG, 30, 30000 IJK, 28, 41000 EFG, 31, 28000 EFG, 29, 35000
81st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
041st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
05// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
4// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
51st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
51st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
0Ví dụ 3:
salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
2salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
8salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
6salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
2salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
2salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
6salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
7ABC, 24, 18000 EFG, 30, 30000 IJK, 28, 41000 EFG, 31, 28000 EFG, 29, 35000
81st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
30// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
8// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
91st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
1// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
2// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
3// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
4// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
61st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
411st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
421st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
43ABC, 24, 18000 EFG, 30, 30000 IJK, 28, 41000 EFG, 31, 28000 EFG, 29, 35000
81st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
45// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
8// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
91st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
1// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
2// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
3// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
4// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
6ABC, 24, 18000 EFG, 30, 30000 IJK, 28, 41000 EFG, 31, 28000 EFG, 29, 35000
81st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
571st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
581st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
591st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
60// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5Ví dụ 2:
// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
8// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
91st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
1// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
2// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
3// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
4// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
61st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
76Output:
1st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
2- Ví dụ 2:
1st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
51st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
0salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
21st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
8salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
4salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
2salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
8salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
6salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
2salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
2salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
6salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
7ABC, 24, 18000 EFG, 30, 30000 IJK, 28, 41000 EFG, 31, 28000 EFG, 29, 35000
81st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
30// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
8// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
91st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
1Ví dụ 2:
// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
6ABC, 24, 18000 EFG, 30, 30000 IJK, 28, 41000 EFG, 31, 28000 EFG, 29, 35000
8var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
10// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
12var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
13var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
14// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
8// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
91st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
1// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
2// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
3// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
4// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
61st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
76Output:
1st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
3 - Ví dụ 2:
1st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
51st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
0salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
21st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
8salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
4salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
2salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
8salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
6salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
2salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
1salary[3][3] = "India"; // It adds "India" at the 4th index of 4th sub-array, // If we print the entire 4th sub-array, document.write[salary[3]]; // the output will be : ["EFG", 31, 28000, "India"] // indexing starts from 0
2var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
2salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
6salary[3].push["India", "Mumbai"]; // It add "India" at the 4th index and "Mumbai" at // 5th index of 4th sub-array // If we print the entire 4th sub-array, // document.write[salary[3]]; // The output will be : ["EFG", 31, 28000, "India", "Mumbai"] // Indexing starts from 0
7ABC, 24, 18000 EFG, 30, 30000 IJK, 28, 41000 EFG, 31, 28000 EFG, 29, 35000
81st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
30// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
8// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
91st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
1// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
2// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
3// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
4// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
6ABC, 24, 18000 EFG, 30, 30000 IJK, 28, 41000 EFG, 31, 28000 EFG, 29, 35000
8var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
58var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
591st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
59var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
61// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
63// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
8// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
91st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
1// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
2// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
3// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
4// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
6ABC, 24, 18000 EFG, 30, 30000 IJK, 28, 41000 EFG, 31, 28000 EFG, 29, 35000
8var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
74// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5var salary = [ ["ABC", 24, 18000], ["EFG", 30, 30000], ["IJK", 28, 41000], ["EFG", 31, 28000], ];
76// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
8// This notation access the salary of "ABC" person which is 18000, // [0] selects 1st row, and [2] selects the 3rd element // of that 1st row which is 18000 salary[0][2]; // Similarly, salary[3][2]; // Selects 28000 **This notation is used for both Method 1 and Method 2.
91st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
6// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
1// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
2// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
3// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
4// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
5// This loop is for outer array for [var i = 0, l1 = salary.length; i < l1; i++] { // This loop is for inner-arrays for [var j = 0, l2 = salary[i].length; j < l2; j++] { // Accessing each elements of inner-array documents.write[ salary[i][j] ]; } }
61st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
76Output:
1st, need to define some 1D array var arr1 = ["ABC", 24, 18000]; var arr2 = ["EFG", 30, 30000]; var arr3 = ["IJK", 28, 41000]; var arr4 = ["EFG", 31, 28000]; var arr5 = ["EFG", 29, 35000]; // "salary" defines like a 1D array but it already contains some 1D array var salary = [arr1, arr2, arr3, arr4, arr5];
4
JavaScript được biết đến nhiều nhất để phát triển trang web nhưng nó cũng được sử dụng trong nhiều môi trường không phải là trình duyệt. Bạn có thể tìm hiểu JavaScript từ cơ sở bằng cách làm theo các ví dụ JavaScript và JavaScript này.