P
P
Pavel Grudinkin2016-03-11 16:45:04
JavaScript
Pavel Grudinkin, 2016-03-11 16:45:04

What does [2] do in the given .match?

There is this code:

host_uri.path().match(///^\/([a-z]*\/[a-z].*?\/[a-z].*?)-(.*).*///)[2]


I can't understand what [2] does, I also have an error: "Uncaught TypeError: Cannot read property '2' of null", and I can't figure out where this property is.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HoHsi, 2016-03-11
@Hunt666

[2] does not apply to the regular season at all. This is an array element selection. Since matchin JS (and in all implementations) it returns an array, you simply select the 3rd element. That is:
/^\/([az]*\/[az].*?\/[az].*?)- (.*).*/
What you have there is known only to you.
But now you are trying to take the second 3rd element from Null

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question