-3

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.

2
  • Does this answer your question? How to get the last part of a string in JavaScript? Commented Apr 20, 2022 at 4:06
  • every answer uses str.split('/').pop() ... what about str.substring(str.lastIndexOf('/')+1) - sure, it's longer code, but at least it's not the same answer 3 times :p or str.replace(/^.+\//, "") Commented Apr 20, 2022 at 4:42

2 Answers 2

1

You can use:

function getStr(str) {
   return str.split('\/').pop()
}
Sign up to request clarification or add additional context in comments.

Comments

1

Here:

input.split("\n").map(line => line.split("/").pop())

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.