9 more Javascript Array methods
Tags: webdev, javascript, beginners, programming
Published: 2023-02-10 19:00:00

Array methods are a powerful tool in JavaScript that allow developers to manipulate and transform arrays in various ways. These methods are built-in functions that can be used on any array object, making them an essential part of the JavaScript language. We already explored some array methods in [this](https://dev.to/zuzexx/10-most-used-javascript-array-methods-g2j) article, today we will explore 9 more methods.

## Table of Contents
1. [.find()](#find)
2. [.findIndex()](#findindex)
3. [.includes()](#includes)
4. [.forEach()](#foreach)
5. [.map()](#map)
6. [.sort()](#sort)
7. [.reverse()](#reverse)
8. [.filter()](#filter)
9. [.reduce()](#reduce)

## .find()

The Array.find() method returns the value of the first element in the array that satisfies the provided testing function. It returns undefined if no elements in the array pass the test.

```js
let numbers = [1, 2, 3, 4, 5];
let result = numbers.find(num => num > 3);
console.log(result); // 4

```
</br>

## .findIndex()
The Array.findIndex() method returns the index of the first element in the array that satisfies the provided testing function. It returns -1 if no elements in the array pass the 
test.

```js
let numbers = [1, 2, 3, 4, 5];
let result = numbers.findIndex(num => num > 3);
console.log(result); // 3
```
</br>

## .includes()
The Array.includes() method returns a boolean indicating whether the given value is present in the array.

```js
let numbers = [1, 2, 3, 4, 5];
let result = numbers.includes(3);
console.log(result); // true
```
</br>

## .forEach()

 The Array.forEach() method executes a provided function once for each array element.

```js
let numbers = [1, 2, 3, 4, 5];
numbers.forEach(num => console.log(num));
```
</br>

## .map()

The Array.map() method creates a new array with the results of calling a provided function on every element in the calling array.

```js
let numbers = [1, 2, 3, 4, 5];
let result = numbers.map(num => num * 2);
console.log(result); // [2, 4, 6, 8, 10]
```
</br>

## .sort()

The Array.sort() method sorts the elements of an array in place and returns the sorted array.

```js
let numbers = [5, 3, 1, 4, 2];
numbers.sort();
console.log(numbers); // [1, 2, 3, 4, 5]
```
</br>

## .reverse()

The Array.reverse() method reverses the order of the elements of an array in place and returns the reversed array.

```js
let numbers = [1, 2, 3, 4, 5];
numbers.reverse();
console.log(numbers); // [5, 4, 3, 2, 1]
```
</br>

## .filter()

The Array.filter() method creates a new array with all elements that pass the test implemented by the provided function.

```js
let numbers = [1, 2, 3, 4, 5];
let result = numbers.filter(num => num > 3);
console.log(result); // [4, 5]
```
</br>

## .reduce()

The Array.reduce() method executes a reducer function (that you provide) on each element of the array, resulting in a single output value.

```js
let numbers = [1, 2, 3, 4, 5];
let result = numbers.reduce((accumulator, currentValue) => accumulator + currentValue);
console.log(result); // 15
```
</br>

#Conclusion:

In conclusion, these array methods are essential for working with arrays in JavaScript. They allow developers to manipulate, sort, filter, and transform arrays in various ways. Whether you're working on a simple or complex project, understanding how to use these methods will make your work more efficient and effective. I hope this article has given you a good overview of the most commonly used array methods in JavaScript, and how they can be applied in real-world scenarios.