The JavaScript array allows you to store several pieces of data in one place. The elements of an array are stored in square brackets […]. Every element in an array is separated by a comma “, ”. The elements of an array can be any data type.

For example:

Creating an array…

var fruits = ["mango", "orange", "apple"];

How to select any item from an array

You can access array data with indexes. The index number is written in a square bracket and it starts from 0 i.e 0 is the first element.

Let’s see an example…

let fruits = ["mango", "orange", "apple"];
let myFruits = fruits[0];
alert(myFruits);

The index number [0] will select the first fruit in the array which is “mango”. This would be the output of the alert pop-up.

How to remove the last element from an array

An item can be removed from an array with the javascript pop function pop().

For example…

let scores = [27, 46, 75];
alert(scores); //check pop up to see the array data

//remove the last element from the array
let changeLastScore = scores.pop(); 
alert(scores);

The last score on the data set which is “75” has been removed from the array. 

Remove the last element of a nested array with JavaScript pop function

When one of the elements of an array is another array, it is called a nested array. 

For example…

let classes = [["Quantum Physics ", 16], [" Modern Biology ", 9], [" Robotics ", 4]];

To remove the last element of any of the nested arrays we just have to select the data set using an index number and then use the pop() function.

For example, we are going to remove the number from the last element of the nested array which is “4”.

let classes = [["Quantum Physics ", 16], [" Modern Biology ", 9], [" Robotics ", 4]];
alert(classes);
    
let removeRoboticsNumber= classes[2].pop();
alert(classes);

Conclusion:

Try with various examples to master the code. You can create a shopping list that would consist of nested arrays and then try to remove the last element from each nested array.