![]() |
Generally, in JavaScript, we deal with one-dimensional or linear arrays that contain multiple elements of the same type stored at different memory locations with the same name. But, there are also 2D array concepts that exist in JavaScript. What are 2D Arrays?A 2D array is commonly known as an array of arrays in JavaScript. It is an array that consists of multiple arrays stored at different memory locations but with the same name. The 2D arrays are just like the matrices in mathematics. Every cell of the array can be considered as a row and the array contained by that particular cell can be considered as columns. Example:[ NOTE: JavaScript does not provide any direct syntax to create 2D arrays. However, you can use the jagged array syntax or the array of arrays syntax to create 2D arrays in JavaScript. What is the use of 2D arrays?The 2D arrays can be used to store and manipulate the data in a structured or organized manner. Below listed some of general use cases of the 2D arrays in JavaScript.
Example 1: The below code example shows how you can define a 2D array in JavaScript. Javascript
Output
2D Arrays in JS: [ [ 1, 2, 3 ], [ 'str1', 'str2' ], [ true, false ] ] Example 2: The below code explains how you can access the 2D array elements in JavaScript. Javascript
Output
First array last element: 3 Second array second element: str2 Third array first element: true Limitations of 2D arrays
|
Reffered: https://www.geeksforgeeks.org
JavaScript |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 19 |