How to delete last character from a string using jQuery?

后端 未结 5 1233
夕颜
夕颜 2020-12-22 16:58

How to delete last character from a string for instance in 123-4- when I delete 4 it should display 123- using jQuery

5条回答
  •  长情又很酷
    2020-12-22 17:35

    You can do it with plain JavaScript:

    alert('123-4-'.substr(0, 4)); // outputs "123-"
    

    This returns the first four characters of your string (adjust 4 to suit your needs).

提交回复
热议问题