# JavaScript built-in Methods

Coming from very different background and profession, like many of you I’ve never coded before. I’ve wanted to learn to code for a long time, but I never had a clear road map to start with. The time has finally come in my late 30’s, and now here I am. During my learning journey I found that javascript built-in methods are really amazing. So I am going to talk about javascript built-in methods here in this blog post. I hope it will help other beginners like me understand javascript methods better and gain some knowledge. 

### What is a Javascript Array  methods?

Array methods are built-in functions that can be invoked on arrays to perform various operations task efficiently such as adding, removing, modifying or iterating over elements within the array.

### Why are methods important?

  
Methods are important because they provide built-in  functions for performing various operations on data structures like array and objects enabling developers to manipulate data and create dynamic and interactive web applications efficiently .

The following are some common javascript array methods:

.**push(), .pop(), .shift(), .unshift(), .splice(), .slice(), .forEach(), .map,(), .filter(), .find(), .sort(), .reduce()**  

**push( )** 

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712081238781/4d115ca5-ad23-4d21-bb15-add42842f1ac.png align="left")

The <mark>push( )</mark> method adds the element(5) to the end of the array of numbers.

**pop( )**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712081314371/caefdf80-f3e2-4a7a-a64e-f7598b23a287.png align="center")

The <mark>pop( )</mark> method removes the last element from the array. After executing the pop() method, the array of fruits contains one less element and the removed fruit is stored in the removeFruit variable.

**shift( )** 

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712081434085/b3934f06-1208-42ba-871a-57714e209625.png align="center")

After executing the <mark>shift( ) </mark> method, it removes the first  element from the array and stores it in the removeFruit variable.

**unshift( )**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712081519826/f672e287-43f0-45ca-81c9-46ed57610d78.png align="center")

<mark>unshift()</mark> methods add the element  to the beginning of the array . In this case ‘mango’ is added at the beginning 

**splice( )** 

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712081582332/d5d108d3-81aa-40fc-83d6-12727a22c6a4.png align="center")

The <mark>splice( )</mark> method removed the elements from the array based on the specified starting index, and the number of elements to remove. In this case it removed 2 elements starting from index 1: “banana” and “orange”. The removed elements are stored in removeFruit variable. The fruits array contains remaining elements after the removal.

**slice( )** 

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712081649752/5436d39f-b57b-4eb0-9800-b0dab5024401.png align="center")

The <mark>slice( )</mark> method creates a shallow copy of a portion of the array based on the specified start and end indices. It does not modify the original array. In this case it slices elements from index 1 to index 2 (exclusive).The resulting sliceFruits variable contains the sliced elements ‘banana’ and ‘orange’, and fruits array remains unchanged.

**forEach( )** 

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712081711551/dcb6425a-001e-4a27-97db-3b7072e4a57a.png align="center")

The <mark>forEach( )</mark> method iterates over each element in the array, and execute the function once for each element. in this case it logs each numbers to the console.

**map( )** 

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712081783775/a45de715-4c7f-49ca-9c14-9f1f6075f852.png align="center")

The <mark>map( )</mark> method iterates over each element and applies to each element. Here it doubles each number and stored it to the '*doubleNums*' variable.

**filter( )**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712081947290/38411660-dad2-4d6d-b04f-9335728d1c30.png align="center")

 Here the <mark>filter( )</mark> method filters out the odd numbers and outputs them to the *oddNums* variable.

**find( )**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712082013540/9dfd47bd-59c1-4811-86ad-a1278d3d0531.png align="center")

in this example <mark>find( )</mark> method searches for user ID of 2 and returns the corresponding user object if the condition matches  are true ?

**sort( ).**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712082180154/dded0e41-68f8-460e-976c-a5795db0e1b6.png align="center")

The <mark>sort( )</mark> method sorts the array elements as strings in unicode order. Therefore the array numbers are sorted in ascending order.

**reduce( )**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1712082248758/9bcb47fb-d178-462d-81aa-1b938d642d16.png align="center")

The <mark>reduce( )</mark> method takes two arguments an accumulator which accumulate and store the result and the current element being processed here . the initial value of the accumulator is specified as 0 and the it adds each element to the accumulator resulting in the sum of all numbers in the array.

These are just few examples of array methods in javascript. Array methods offer powerful functionalities for working with arrays efficiently and effectively. I encourage you to try them out and see what you can do with them yourself.

Let me know in the comments what are some of your favorite things about array methods, and which you find to be the most useful. Happy coding 😺
