Arrays are fundamental data structures in JavaScript, allowing you to store and manipulate collections of data. Here's a concise overview:
🌟 Key Features
- Ordered: Elements are stored in a specific sequence
- Indexed: Accessible via numerical indices (0-based)
- Dynamic: Can change size at runtime
- Heterogeneous: Can hold elements of different types
🧱 Creating Arrays
// Syntax
let fruits = ["apple", "banana", "orange"];
let numbers = new Array(1, 2, 3);
🛠️ Common Methods
Method | Description | Example |
---|---|---|
push() |
Add elements to the end | fruits.push("grape") |
pop() |
Remove last element | fruits.pop() |
slice() |
Extract a portion | fruits.slice(1, 3) |
map() |
Transform elements | numbers.map(x => x * 2) |
📌 Example Use Case
let techStack = ["React", "Node.js", "MongoDB"];
techStack.forEach(item => console.log(`Using: ${item}`));
📚 Related Topics
For deeper understanding, check:
JavaScript Array Operations
Array Methods Reference