Arrays
Arrays are one of the most fundamental data structures in programming. They are used to store multiple values in a single variable, allowing for efficient data manipulation and access. This guide will cover how to declare, initialize, and work with arrays in JavaScript, Java, Python, and C++.
What is an Array?
An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together to make it easier to manage them. Arrays can be indexed, modified, and iterated over to perform various operations.
Arrays in Different Languages
- JavaScript
- Java
- Python
- C++
JavaScript Arrays Overview
In JavaScript, arrays are dynamic, which means they can change size and hold mixed data types.
Video Explanation

Declaration and Initialization
// Declaration
let fruits = ["Apple", "Banana", "Cherry"];
// Accessing elements
console.log(fruits[0]); // Output: Apple
// Modifying an array
fruits[1] = "Mango";
console.log(fruits); // Output: ["Apple", "Mango", "Cherry"]
Common Array Methods
push(): Adds an element to the end.pop(): Removes the last element.shift(): Removes the first element.unshift(): Adds an element to the beginning.
fruits.push("Orange");
console.log(fruits); // Output: ["Apple", "Mango", "Cherry", "Orange"]
fruits.pop();
console.log(fruits); // Output: ["Apple", "Mango", "Cherry"]
Java Arrays Overview
Java arrays have a fixed size and must be declared with a type.
Video Explanation

Declaration and Initialization
// Declaration
int[] numbers = new int[5]; // Array of size 5
// Initialization
int[] primes = {2, 3, 5, 7, 11};
// Accessing elements
System.out.println(primes[2]); // Output: 5
// Modifying an array
primes[2] = 13;
System.out.println(primes[2]); // Output: 13
Looping Through Arrays
for (int num : primes) {
System.out.println(num);
}
Python Arrays (Lists) Overview
In Python, lists are dynamic and can hold different data types.