'String processing, get last string in vuejs? [closed]
i am dealing with strings in vuejs. Now I have 4 url strings:
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
Now I want to process to get the final string. Since my string is not fixed length using fixed ways is not efficient. Result I want to get :
apple-iphone-13
samsung-galaxy
xiaomi-red
apple-ipad
Everyone please give me any comments, thanks.
Solution 1:[1]
You can use:
function getStr(str) {
return str.split('\/').pop()
}
Solution 2:[2]
Here:
input.split("\n").map(line => line.split("/").pop())
Solution 3:[3]
[
'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())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tanay |
| Solution 2 | User81646 |
| Solution 3 | Abhishek Shastri |
