This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center




7年前关闭。




我们如何使用JavaScript / jQuery从字符串中获取最后一个单词?

在以下情况下,最后一个单词是“衣领”。单词之间用“-”分隔。
Closed-Flat-Knit-Collar
Flat-Woven-Collar
Fabric-Collar
Fabric-Closed-Flat-Knit-Collar

最佳答案

为什么所有内容都必须在jQuery中?

var lastword = yourString.split("-").pop();

这会将您的字符串拆分为各个部分(例如,ClosedFlatKnitCollar)。然后它将弹出数组的最后一个元素并返回它。在您给出的所有示例中,这都是Collar

08-05 07:19