DEV Community

Discussion on: 4 Ways to Remove the Last Character from a String in JavaScript 🚮

Collapse
 
arabelhousseyn profile image
elhousseyn arab

this one is not optimized
const bookName = 'Atomic Habits'

// We create an array: ['A', 't', 'o', 'm', 'i', 'c', ' ', 'H', 'a', 'b', 'i', 't', 's']
const bookNameArray = bookName.split(''
// We delete the last element (letter 's')
bookNameArray.pop()

// We convert back the array to a string
const newBookName = bookNameArray.join('')

console.log(newBookName)