🔷 1. Creating Arrays
let arr = [1, 2, 3];
let fruits = new Array("apple", "banana");
---
🔶 2. Accessing Elements
arr[0]; // First element
arr.length; // Number of elements
---
🟢 3. Adding/Removing Elements
arr.push(4); // Add to end
arr.pop(); // Remove from end
arr.unshift(0); // Add to start
arr.shift(); // Remove from start
---
🔵 4. Iterating Over Arrays
for (let i = 0; i arr.length; i++) { ... }
arr.forEach((item) = console.log(item));
---
🟣 5. Common Array Methods
map(): Creates new array by applying function
arr.map(x = x * 2);
filter(): Filters based on condition
arr.filter(x = x 2);
find(): Returns first match
arr.find(x = x === 2);
includes(): Checks if value exists
arr.includes(2);
indexOf(): Gets index of value
arr.indexOf(3);
splice(): Adds/removes elements by index
arr.splice(1, 2); // Remove 2 elements from index 1
slice(): Returns a portion of the array
arr.slice(1, 3); // Elements from index 1 to 2
---
🟤 6. Sorting and Reversing
arr.sort(); // Alphabetical sort
arr.reverse(); // Reverse the array
---
⚪ 7. Combining and Joining
arr.concat([4,5]); // Merge arrays
arr.join("-"); // Join elements to string
---
⚫ 8. Checking Array Type
Array.isArray(arr); // true