我正在努力保持 split 的尾端
myLink = link.split(/\d/, 2)[1]
不管它分割的是什么字符串
link = 1 some text 800 hello world
会像这样 split :
1,
some text
我最终失去了尾端 800 hello world
。
我该怎么做才能保留这些信息。
最佳答案
这是因为您将 2 的限制传递给 split 函数,所以您在 split 数组中只得到两个结果。省略 2,你会得到它们:
var splitArray = link.split(/\d/);
关于javascript - split 导致尾端丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13742186/