1array.pop(); //returns popped element
2//example
3var fruits = ["Banana", "Orange", "Apple", "Mango"];
4fruits.pop(); // fruits= ["Banana", "Orange", "Apple"];
1var array = [1, 2, 3, 4, 5, 6];
2array.pop();
3console.log(array);
4//Output in console section:
5//[1, 2, 3, 4, 5]
1const cars = ['Porsche', 'Ferrari', 'Mustang', 'Rolls Royce', 'Lamborghini'];
2
3console.log(cars.pop());
4// expected output: 'Lamborghini'
5
6console.log(cars);
7// expected output: Array ['Porsche', 'Ferrari', 'Mustang', 'Rolls Royce']
1const plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato'];
2
3console.log(plants.pop());
4// expected output: "tomato"
5
6console.log(plants);
7// expected output: Array ["broccoli", "cauliflower", "cabbage", "kale"]
1 let array = ["A", "B", "C"];
2
3//Removes the last element of the array
4 array.pop();
5
6//===========================
7 console.log(array);
8//output =>
9//["A", "B"]
10
11//if you want to remove more varibles in the array,
12//insted of using push you can simply define the length of the array
13 let array1 = [1, 2, 3, 4, 5, 6];
14
15//Defines the length of the array to 2, removing the elements
16//after the second element
17 array1.length = 2;
18
19//===========================
20 console.log(array1);
21//output =>
22//["1", "2"]
23
1var cars = ['mazda', 'honda', 'tesla'];
2var telsa=cars.pop(); //cars is now just mazda,honda