Jammming | step 79: check Acces token match


Currently working on:
step 79:
To set the acces token to the acces token in URL (user acces token) the line in code is:
AccesToken = accesTokenMatch[1];

Question 1:
Is seems as if the acces token is found in an array while it is in the URL (?) and if so, why is the acces token in index 1 and not 0?
Same for expiration time.
Where to look to find more documentation on this specific topic?

thank you!

Hi there

If you set up some dummy search code you can see what ‘match’ returns:

const urlString = 'testurl.com/#access_token=testaccesstoken&othertoken=anothertoken&so-on'

const accessTokenInURL = urlString.match(/access_token=([^&]*)/)



  index: 13,
  input: 'testurl.com/#access_token=testaccesstoken&othertoken=anothertoken&so-on',
  groups: undefined

The set of () parentheses in the search expression makes the text following the ‘access_token=’ a capture group; which puts it into its own element in the match array.

If you take the parentheses out and run the dummy code again the result is:

  index: 13,
  input: 'testurl.com/#access_token=testaccesstoken&othertoken=anothertoken&so-on',
  groups: undefined

without the helper step of separating the token from the key.

More on MDN: regular expressions

Hope this helps :grinning:

Thanks Sam!

I think I get it :grinning:
I’m going to chew on this one a bit… next stop; regex, I guess. :slight_smile:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.