Replace last character of string using JavaScript

后端 未结 3 1493
天涯浪人
天涯浪人 2021-01-31 01:10

I have a very small query. I tried using concat, charAt, slice and whatnot but I didn\'t get how to do it.

Here is my string:

var str1 = \"Notion,Data,I         


        
3条回答
  •  执念已碎
    2021-01-31 02:06

    You can do it with regex easily,

    var str1 = "Notion,Data,Identity,".replace(/.$/,".")
    

    .$ will match any character at the end of a string.

提交回复
热议问题