0
Q:

how to remove last element in js

var str = "Hello";
var newString = str.substring(0, str.length - 1); //newString = Hell
14
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
let str = "12345.00";
str = str.substring(0, str.length - 1);
console.log(str);
0
arr.splice(-1,1)
2
const text = 'abcdef'
const editedText = text.slice(0, -1) //'abcde'
0
array.splice(-1,1)
0

New to Communities?

Join the community