2

I have the following string /products/id/edit'

i want to get the substring products using javascript but i am not sure how to do it? Any pointers will be great. Thanks

1 Answer 1

1

String objects have a .split() method:

'/products/id/edit'.split('/')

Which outputs a four member array; one for each string around the slashes:

["", "products", "id", "edit"]

Does that accomplish what you're hoping for?

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for trying to help. I need to figure out how to use that snippet tool, but for now I can just be more verbose.
press Ctrl+M in the answering window and use it
Keeps showing a script error for simple and perfectly valid JS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.