SimonH
0
Q:

how to remove last element of array in javascript

var colors = ["red","blue","green"];
colors.pop();
12
array.pop();   //returns popped element
//example
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.pop();  // fruits= ["Banana", "Orange", "Apple"];
10
var array = [1, 2, 3, 4, 5, 6];
array.pop();
console.log(array);
//Output in console section:
//[1, 2, 3, 4, 5]
3
array.pop();

// Example
var colors = ['Yellow', 'Red', 'Blue', 'Green'];
var removedColor = colors.pop(); // Green
console.log(colors); // ['Yellow', 'Red', 'Blue']
1
arr.splice(-1,1)
2
array.splice(-1,1)
0
let numbers = [1, 2, 3];
numbers.pop();
0

var fruits = ["Banana", "Orange", "Apple", "Mango"];

fruits.pop();
 
0

New to Communities?

Join the community