- Регистрация
- 1 Мар 2015
- Сообщения
- 1,481
- Баллы
- 155
| Method | Purpose | Example Usage | Returns |
|---|---|---|---|
| map() | Transforms each element and returns a new array | arr.map(x => x * 2) | New array |
| filter() | Returns array of elements that pass the test in the callback | arr.filter(x => x > 0) | New array |
| reduce() | Reduces array to single value by applying a function | arr.reduce((a, b) => a + b, 0) | Single value |
| forEach() | Runs a function on each array element (no return) | arr.forEach(x => console.log(x)) | undefined |
| find() | Finds the first element that passes the test | arr.find(x => x > 10) | Element or undefined |
| findIndex() | Finds the index of the first element passing the test | arr.findIndex(x => x > 10) | Index or -1 |
| some() | Checks if any element passes the test | arr.some(x => x < 0) | true/false |
| every() | Checks if all elements pass the test | arr.every(x => x > 0) | true/false |
| includes() | Checks if array contains a value | arr.includes(2) | true/false |
| indexOf() | Finds index of value in array (-1 if not found) | arr.indexOf(2) | Index or -1 |
| push() | Adds elements to end, returns new length | arr.push(4) | New length |
| pop() | Removes last element, returns removed value | arr.pop() | Removed element |
| shift() | Removes first element, returns removed value | arr.shift() | Removed element |
| unshift() | Adds elements to start, returns new length | arr.unshift(1) | New length |
| slice() | Returns part of array, does not modify original | arr.slice(1, 3) | New array |
| splice() | Changes array by adding/removing elements | arr.splice(1, 2) | Removed elements |
| concat() | Combines arrays, returns new array | arr.concat([4,5]) | New array |
| join() | Joins all elements into a string | arr.join('-') | String |
| reverse() | Reverses array in place | arr.reverse() | Same array |
| sort() | Sorts array in place | arr.sort() | Same array |
| flat() | Flattens nested arrays | arr.flat() | New array |
| fill() | Fills array with static value | arr.fill(0) | Same array |
| from() | Creates array from array-like object | Array.from('abc') | New array |
| isArray() | Checks if a value is an array | Array.isArray(arr) | true/false |