0

The code:

var numFriends = 30;

var arr = document.body.innerHTML.match(/inviteFriend\(\'(\d+)\',5\)/gm);

for (var i = 0; i < numFriends; i++) {
  friendInvited({}, (/inviteFriend\(\'(\d+)\',5\)/gm.exec(arr[i]))[1]);
};

Entering the code in console in Firefox returns the following error:

TypeError: arr is null

And in Chrome:

TypeError: Cannot read property '0' of null

Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
Kay
  • 1
  • 1
  • 4
    Maybe... your regular expression doesn't match anything on the page? – Matti Virkkunen Nov 24 '14 at 02:26
  • 1
    The **match()** method returns an Array containing the matched results or null if there were no matches. If `arr` is indeed `null` then the error message you described is exactly what happens. I'd suggest testing the regex to make sure it will match what you intend. You can use an online resource like [Regex101.com](http://regex101.com/) to do just that. – Edgar Sanchez Nov 24 '14 at 05:47

0 Answers0