Split variable using a special character in JavaScript

后端 未结 4 880
夕颜
夕颜 2021-02-03 22:34

I have a variable var i = "my*text" I want to split it using special character *. I mean, I want to generate var one = "my&

4条回答
  •  不思量自难忘°
    2021-02-03 23:12

    Just to add, the comma operator is your friend here:

    var i = "my*text".split("*"), j = i[0], k = i[1];
    alert(j + ' ' + k);
    

    http://jsfiddle.net/EKB5g/

提交回复
热议问题