Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有如下代码
var data = "(5)"
现在,使用拆分我只需要数字“5”,需要截断“(”和“)”。
如果你真的想使用拆分,
var data = "(5)" alert(data.split(')')[0].split('(')[1])
如果你知道你会有这种模式(前导 + 尾随括号),只需 slice :
"(5)".slice(1, -1);
不使用split,使用replace。
split
replace
var data - "(5)".replace("(","").replace(")","");