我在用vuejs来处理弦乐。现在我有了4个url字符串:
https://web-sand.com/product/slug/apple-iphone-13
https://web-sand.com/product/slug/samsung-galaxy
https://web-sand.com/product/slug/xiaomi-red
https://web-sand.com/product/slug/apple-ipad现在我想要处理得到最后的字符串。因为我的字符串不是固定长度,所以使用固定方式是不有效的。我想得到的结果是:
apple-iphone-13
samsung-galaxy
xiaomi-red
apple-ipad大家请给我任何意见,谢谢。
发布于 2022-04-20 04:05:22
您可以使用:
function getStr(str) {
return str.split('\/').pop()
}发布于 2022-04-20 04:08:06
在此:
input.split("\n").map(line => line.split("/").pop())
发布于 2022-04-20 04:09:36
[
'https://web-sand.com/product/slug/apple-iphone-13',
'https://web-sand.com/product/slug/samsung-galaxy',
'https://web-sand.com/product/slug/xiaomi-red',
'https://web-sand.com/product/slug/apple-ipad'
].map(item => item.split('/').pop())https://stackoverflow.com/questions/71933948
复制相似问题