Part1: JavaScript Array

Part1: JavaScript Array

Basically! JavaScript array is a collection of data (elements in all types of, such that string, number, boolean, an array). A pair of square brackets represents an array and is separated by ( , ).

Example:

[elementOne, elementTwo, elementThree, elementFour]

code.png

The position of array elements is known as an index and it starts with zero.

code.png

And, the total number of elements defines the length of an array, you can get the length of an array this way.

code.png

Also, you can get specific elements using an index of an array.

code.png

Now let's see another method to assign values in an array but no need to use this method, you can use the first method (literal method)

code.png

Now, we move towards Array methods. There are different types of array methods, let's see one by one.

push() method

Add a new element to an array at the end position.

code.png

pop() method

Remove the last element from an array

code.png

shift()

Remove the first element of an array.

code.png

unshift()

Add an element of an array at the beginning of the array.

code.png

Thank you