Array cheatsheet Javascript
Tags: javascript, beginners, webdev, productivity
Published: 2021-11-29 14:34:10

Variables in Javascript allow only one data to be stored at a time. However, given that it is often useful to manipulate many data, the concept of variable is sometimes insufficient, because it becomes difficult to manage a great number of distinct variables.

To remedy this, Javascript proposes a data structure allowing to store all these data in a "common variable": the array.

An array, in Javascript, is thus a variable which can contain several independent data, indexed by a number, called index. The index of an array is thus the element allowing to access the data stored in it.


**ARRAY LENGTH**
The length method returns the length of the array.



![ARray length](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6nyvii3lvhn0oazpwmox.png)


**ARRAY PUSH()**
The push () method adds one or more elements to the end of an array and returns the new size of the array.


![Push](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgyczaadhzx9a1lme5ba.png)

**ARRAY POP()**
The pop () method removes the last element from an array and returns that element. This method changes the length of the array.


![Pop](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qux3shwj01gzj7uuskq6.png)

**ARRAY UNSHIFT()**
The unshift () method adds one or more elements to the start of an array and returns the new length of the array.


![Unshift](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q9urjlkwic54jggpz4eu.png)

**ARRAY SHIFT()**
The shift () method removes the first element from an array and returns that element. This method changes the length of the array.


![Shift](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6so7hlkk5kjvpc2huyfr.png)

**ARRAY FOREACH()**
The forEach () method iterates through the array elements one by one to perform a function.


![ForEach](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yaqoxm7034cmi6snanyq.png)

**ARRAY FILTER()**
The filter () method creates and returns an array containing the elements that check the filter.


![Filter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/acgl675539c4ik9h8v6v.png)

**ARRAY MAP()**
The map () method returns a new array containing all the elements of the initial array on which the function is called.

![Map](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w9wqr8e563t1jghrpjei.png)

**ARRAY REDUCE()**
The reduce () method applies a function which is an "accumulator" and which processes each value in the array (from left to right) to reduce it to a single value.


![Reduce](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7egdwmkm2h1aig3v3c8o.png)

**ARRAY SLICE()**
The slice () method returns an array, containing a copy of part of the original array, the portion is defined by a start index and an end index (excluded). The original array will not be modified.


![Slice](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s4dxe3daf4lnxeau3j5t.png)

**ARRAY CONCAT()**
The concat () method is used to merge one or more arrays by concatenating them. This method does not modify existing arrays, it returns a new array which is the result of the operation.


![Concat](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ou1f14ps9pk2gq4551fj.png)

**ARRAY JOIN()**
The join () method creates and returns a new character string by concatenating all the elements of an array. The concatenation uses the comma or another string, supplied as an argument, as the separator.


![Join](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bedzq2y3n13h3o3ao3to.png)

**ARRAY REVERSE()**
The reverse() method reverses an array. The first array element becomes the last, and the last array element becomes the first.


![Reverse](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t52uklor18kxdwyfndub.png)