gpt4 book ai didi

jquery - 用最后一个逗号分割字符串

转载 作者:行者123 更新时间:2023-12-03 22:56:01 24 4
gpt4 key购买 nike

我有 jQuery 字符串。

var s = "Text1, Text2, Text,true";

我需要将此变量分成两部分:

var s1 = substring(...); //after this s1="Text1, Text2, Text"
var s2 = substring(...); //after this s2="true"

你能帮我拆分变量吗?

最佳答案

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"

关于jquery - 用最后一个逗号分割字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18249062/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com