Grow your CSS skills. Land your dream job.

Last updated on:

Remove the Last Character from a String

var origString = 'Happy Dance7';
var trimmedString = origString.substring(0, origString.length-1);
console.log(trimmedString);
// 'Happy Dance'

Comments

  1. There’s a way shorter way :-)

    "Happy Dance7".slice(0,-1) //"Happy Dance"
  2. Permalink to comment#

    Or, you could use slice();

    var origString = ‘Happy Dance7′;
    var trimmedString = origString.slice(0,-1);
    console.log(trimmedString);

  3. Permalink to comment#

    Shorter code is better. Thanks to jQuery.

Leave a Comment

Current day month ye@r *

*May or may not contain any actual "CSS" or "Tricks".