Tuesday, December 6, 2016

JavaScript Array - 2 Dimensional Array - Q&A

Question:

How do you create an array in JS?
Can you create 2 dimensional array?

Answer

var arr = [1,2,3,4,5,6]; // Define simple array

var arr2d = [[1,2],[3,4],[5,6]]; // Define 2D array



arr[1] = 22; // Push data to simple array

arr2d[0][1] = 22; // Push data to 2D array



alert(arr[1]); // Read data from simple array

alert(arr2d[0][1]); // Read data from 2D array



No comments:

Post a Comment