Kingsley Simon
Kingsley Simon

Reputation: 2210

Splitting occurence of string and getting specific substring javascript

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

Upvotes: 2

Views: 26

Answers (1)

sorak
sorak

Reputation: 2633

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?

Upvotes: 1

Related Questions