Javascript Array
1. Creating Arrays
const fruits = ["Apple", "Banana", "Mango"];
console.log("Fruits:", fruits);
2. Creating New Arrays by using Array Constructor
let numbers = new Array(1, 2, 3, 4);
3. Adding & Removing Elements
push() → Add to end
pop() → Remove from end
unshift() → Add to start
shift() → Remove from start
4. Finding Elements
indexOf() → First occurrence index
includes() → Check existence
find() → First element matching condition
findIndex() → Index of first match
filter() → Keep elements matching condition
reduce() → Accumulate values
6. Sorting & Reversing
sort() → Sort alphabetically
reverse() → Reverse order
7. Joining & Splitting
join() → Combine into string
split() → Convert string to array
8. Combining & Slicing
concat() → Merge arrays
slice() → Extract portion
splice() → Add/Remove elements
9. Flattening Arrays
flat() → Flatten nested arrays
10. Iterating
forEach() → Loop through elements

No comments:
Post a Comment