1

I have this:

$location.path() // categoria/1-ropa

I want just the id (is 1 in this case)

var path = $location.path().substr(10, $location.path().length); 
var idBusqueda = path.substr(0, path.indexOf('-'));

with this i do that, but i want know if i can do it in one line?

Greets

2 Answers 2

1

My proposal is:

var result = ("categoria/111-ropa".match(/\/(\d+)-/) || [null, null])[1];
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks to both, i prefer this because is more restricted.
0

If you have only one parameter named id , then you can simply use javascript line to get the value:

var result = location.search.split('id=')[1];

Comments

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.