Array Method

Array Method

Array method in JavaScript

Table of contents

What is An Array?

The array is a collection of similar data types. For example, if I want to store any number or name so we can store it easily in our memory. First of all, we have to create an array like

let names =["Tanvi", "Vishali", "Priyanka"]

console.log(names)

1. Array length():

First of all, the array length is used to count how many numbers or sets are given in the array.

  1. Reverse an array():

In this reverse, we can reverse the number in the array.

  1. Push():

In this method, we can add new items to the end of the array.

4.Unshift():

It is the same as the push method. But there is only one difference in the push method we can add items at the end of the array. While in unshift() we can add an item at the start of the array.

5.Array.from():

In this method, we can make a new array from the first array. simply we can copy that array and we can edit it means we can do some changes that the old array.

6.pop():

In this method, we can remove the last item of the array.

7.shift():

This method, it is the opposite of the pop method. In the pop method, it removes from the last item and in the shift method, it removes from the first item.

  1. splice method:

This method, It lets you change the content of your array by removing or replacing existing elements with new ones. This method modifies the original array and returns the removed elements as a new array.

9. Fill method():

The JavaScript array fill() method fills the elements of the given array with the specified static values. This method modifies the original array.

To conclude, there are many array methods which are used to store multiple values in a single memory.

*