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

Posting Code

  • Use Markdown, and it will escape the code for you, like `<div class="cool">`.
  • Use triple-backticks for blocks of code.
    ``` 
    <div>
      <h1>multi-line block of code</h1>
      <span>be cool yo.</span>
    </div>
    ```
  • Otherwise, escape your code, like <code>&lt;div class="cool"&gt;</code>. Markdown is just easier though.

Current ye@r *

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