DEV Community

[Comment from a deleted post]
Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

Why not just this?

console.log(str.slice(0,-1));

or

console.log((a=[...str]).pop()&&a.join(''));

if you want to be fancy!

Collapse
 
sait profile image
Sai gowtham

-1 and str.length-1 are same in slice method but beginners get confused what -1 does here ? To avoid the confusion I used str.length-1 in both examples.

Collapse
 
ctrlsquid profile image
zach

I'd love to see the method mentioned by Jon as a bonus method, with explanation as to what the -1 does so beginners can understand