Arrays
Array
Array is a type of linear Data structure OR
Array is a collection of more than one data but all the data items are same data types, & stored that data in a computer in a contiguous memory location.
...
1
2
3
4
5
...
1 Bytes = 8 bit
Memory is a long tap of Bytes.
Types of Array:
1. One Dimensional Array:
The array with only subscript that array is called as One Dimensional Array.
Example: int a[5]; ← subscript.
2. Two Dimensional Array:
The array with two subscript that array is called as Two Dimensional Array.
Example: int a[5][5]; ← subscript.
3. Multi-Dimensional Array:
The array with more than two subscript that array is called as Multi-Dimensional Array.
Example: Creating and Using Arrays in JavaScript
// One-dimensional array
let numbers = [1, 2, 3, 4, 5];
console.log(numbers[0]); // Output: 1
// Two-dimensional array
let matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
console.log(matrix[1][1]); // Output: 5
// Iterating through an array
for(let i = 0; i < numbers.length; i++) {
console.log(numbers[i]);
}