Why not just this?
console.log(str.slice(0,-1));
or
console.log((a=[...str]).pop()&&a.join(''));
if you want to be fancy!
-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.
-1
str.length-1
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
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Why not just this?
or
if you want to be fancy!
-1andstr.length-1are same in slice method but beginners get confused what-1does here ? To avoid the confusion I usedstr.length-1in both examples.I'd love to see the method mentioned by Jon as a bonus method, with explanation as to what the
-1does so beginners can understand