Skip to main content

Command Palette

Search for a command to run...

Let's Check Out Array And Its 10 Commonly Used Methods

Published
2 min readView as Markdown

As we all know, an array is a collection of homogeneous types of data types

Arrays are generally described as "list-like objects"; they are basically single objects that contain multiple values stored in a list. Array objects can be stored in variables and dealt with in much the same way as any other type of value, the difference being that we can access each value inside the list individually, and do super useful and efficient things with the list, like loop through it and do the same thing to every value. Maybe we've got a series of product items and their prices stored in an array, and we want to loop through them all and print them out on an invoice while totaling all the prices together and printing out the total price at the bottom.

.pop()

This will delete the last array element from the area. For example, we will create an array that will store the results of a sports tournament. The participant who arrives last has to leave the sport. The names of the participants who are coming are [Nikil, Sahil, Ashil, Ajay, Pravesh]. Now, we want to eliminate Pravesh because he arrives last, so we use the pop method to eliminate Pravesh from the array.

.push()

This method is used to add a value in an array; for example, we have an array of names of class students; when a new student comes to school for admission then

.length()

This array method is used to calculate the actual length of the array