用最后一个逗号分隔字符串

tit*_*ans 3 string jquery

我在jQuery中有字符串.

var s = "Text1, Text2, Text,true";
Run Code Online (Sandbox Code Playgroud)

我需要将这个变量拆分为两部分:

var s1 = substring(...); //after this s1="Text1, Text2, Text"
var s2 = substring(...); //after this s2="true"
Run Code Online (Sandbox Code Playgroud)

你能帮我拆分变量吗?

Ion*_*zău 10

var s="Text1, Text2, Text,true";
var lastIndex = s.lastIndexOf(",")

var s1 = s.substring(0, lastIndex); //after this s1="Text1, Text2, Text"
var s2 = s.substring(lastIndex + 1); //after this s2="true"
Run Code Online (Sandbox Code Playgroud)

  • @Jimmy我也想到了.:-) 更新. (2认同)