10

How do I remove the last 4 characters in a string?

'abcdefghijklmnopqrstuvwxyz' to 'abcdefghijklmnopqrstuv'

Answer: slice(0,-4)

Jonyang
  • 103
  • 1
  • 8
  • 1
    +1 for adding the answer. From API docs "If endIndex is a negative number, the ending point is determined by counting back from the end of the string, where -1 is the last character" – Drenai Jul 07 '11 at 11:14
  • 1
    @Johnyang Props for **putting your answer in your question**. The OCD in me is also asking to **see your answer as an accepted answer too** *that is, as an answer with the little green check next to it*. Thanks! – Jacksonkr Aug 07 '11 at 20:09

1 Answers1

3

yourString = yourString.substring( 0, yourString.length - 4 ) would also work, if you need more practice typing and want your cpu to work harder.

Seanonymous
  • 1,304
  • 10
  • 30