例子:var string = "test1, test2, test3, test4, **test5**, test6"输出:test5var string = "test5, test2, **test4**, test7输出:test4
3 回答
九州编程
TA贡献1785条经验 获得超4个赞
<script>
var string = "test1, test2, test3, test4, test5, test6"
var value = string.split(", ").slice(-2, -1)[0] // returns "test5"
console.log( value );
</script>
ibeautiful
TA贡献1993条经验 获得超6个赞
var string = "test1, test2, test3, test4, test5, test6";
var arryOfString= string.split(',');
console.log(arryOfString[arryOfString.length - 2].trim());
希望这会有所帮助
扬帆大鱼
TA贡献1799条经验 获得超9个赞
你可以试试下面的代码
<script>
var string = "test1, test2, test3, test4, test5, test6"
var stringSplit = string.split(",");
var value = stringSplit[(stringSplit.length)-2].trim();
console.log(value);
</script>
添加回答
举报
0/150
提交
取消
