JavaScript Array | Array length, push, pop, shift, unshift, IndexOf, forEach

The topic contains a brief explanation of JavaScript Array and how to create and manipulate JavaScript arrays.

What is an Array

Arrays are the variables that are used to store multiple values in a single variable. This also can be compared with a variable that stores only one variable.
JavaScript arrays can capable to store multiple types of values, including number, string, objects, function, and even other arrays. This makes a more complex data structure like an array of arrays and an array of objects.

JavaScript Array

Create a JavaScript Array

Access an Array Item

On the time accessing an array from a variable we use an array index number. On JavaScript array operation, if you want the last element of an array, use ArrayName.length function and subtract 1 for the last array element.

Add an element at the End of an Array

For adding new array element at the end of an array we use the array push function. Array push function is useful for adding an element to end of an array.

Remove last element in Array

For removing operation in an array element, we use an array pop function. Array pop function removes an array element from last of an array.

Remove from the front of an Array

Using array shift function to remove first element of an array.

Adding the first element to an Array

For adding the first index element in an array we use array unshift function. Check below array unshift function uses the example :

Find the index of an Array Element

For finding the index of an array element we use array indexOf function with array element or value of array parameter. Check the below example for explanation.

Loop in an Array

For getting all elements at once we use a loop in an array. In JavaScript array, we use the forEach loop. In the below example, we print an array element name and its index.

Also Check:

Know more:

Happy Coding..!

Subscribe For Latest Updates

Sign up to best of PHP Code Solutions, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.


My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH, my native place in Odisha. I am a Web Programmer by profession and working on more than 50 projects to date. My passion is working on the web-based project using PHP and relate to all CMS and frameworks which is based on PHP.

4 thoughts to “JavaScript Array | Array length, push, pop, shift, unshift, IndexOf, forEach”

Leave a Reply

Your email address will not be published. Required fields are marked *