jQuery Remove string from string

后端 未结 5 1826
情书的邮戳
情书的邮戳 2021-01-31 00:59

I am trying to remove a string from a string in jQuery.

Here is the string:

username1, username2 and username3 like this post.

I would

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-31 01:35

    If you just want to remove "username1" you can use a simple replace.

    name.replace("username1,", "")

    or you could use split like you mentioned.

    var name = "username1, username2 and username3 like this post.".split(",")[1];      
    $("h1").text(name);
    

    jsfiddle example

提交回复
热议问题