Pig Latin challenge question

In doing this challenge, I ended up checking the challenge hints to figure out what I was doing wrong. I was able to follow the logic and find my mistake, but there’s this one line that I’m having trouble with:

var endLeadCon = str.indexOf(str.match(regex)[0]);

Can anyone tell me exactly what the [0] is doing?
I’m reading this as “variable endLeadCon is equal to where the IndexOf str is equal to the value of str.match(regex)”, but that doesn’t account for [0];

match returns an array of matches, so that is taking the first Character(s) that is matched, and indexOf gives the index of that character in the string

1 Like