JavaScript Array and String Methods (Updated 2025)
# JavaScript Array Methods
Arrays in JavaScript provide powerful built-in methods for manipulation, searching, and iteration.
## Creating & Converting Arrays
- **Array.from()**: Creates an array from iterable objects. Example: `Array.from("hello")`
- **Array.of()**: Creates an array from arguments. Example: `Array.of(1,2,3)`
- **Array.isArray()**: Checks if a value is an array.
## Adding & Removing Elements
- **push()**: Adds element(s) to end. Example: `arr.push(4)`
- **pop()**: Removes last element. Example: `arr.pop()`
- **unshift()**: Adds elements at the beginning. Example: `arr.unshift(0)`
- **shift()**: Removes first element. Example: `arr.shift()`
- **splice()**: Adds/removes elements anywhere. Example: `arr.splice(1,1,"new")`
- **slice()**: Extracts a portion of an array. Example: `arr.slice(1,3)`
## Iteration & Transformation
- **map()**: Transforms elements into a new array. Example: `arr.map(x => x*2)`
- **forEach()**: Iterates but doesn't return a new array.
- **filter()**: Returns a new array with elements matching a condition. Example: `arr.filter(x => x > 10)`
- **reduce()**: Accumulates values. Example: `arr.reduce((acc, num) => acc + num, 0)`
## Searching & Checking
- **find()**: Returns first element that matches condition. Example: `arr.find(x => x > 10)`
- **findIndex()**: Returns index of first match.
- **includes()**: Checks if an element exists.
- **indexOf()**: Finds index of an element.
## Sorting & Reversing
- **sort()**: Sorts elements (lexicographically by default). Example: `arr.sort((a,b) => a-b)`
- **reverse()**: Reverses array order.
# JavaScript String Methods
## Checking & Searching
- **includes()**: Checks if a substring exists.
- **indexOf()**: Finds first occurrence of a substring.
- **startsWith()**: Checks if a string starts with a substring.
- **endsWith()**: Checks if a string ends with a substring.
## Transforming
- **toUpperCase()**: Converts to uppercase.
- **toLowerCase()**: Converts to lowercase.
- **trim()**: Removes whitespace.
- **replace()**: Replaces a substring.
- **replaceAll()**: Replaces all matches.
# Latest ES2025 Updates
- **toSorted()**: Returns a sorted array without modifying the original.
- **toReversed()**: Returns a reversed array without modifying the original.