0

Can anyone please explain this to me? I am running the following code with the following input:

var results = [];
var tokenRegExp = /\s*([A-Za-z]+|[0-9]+|\S)\s*/g;
var m;
while ((m = tokenRegExp.exec(code)) !== null) {
    results.push(m[1].toString() //I added the toString to see if it would change anything, it did absolutely nothing. I was running it without before that);
}
return results;

The input of "code" is 3+3+6*6*5*8/9-6

And then I am seeing this extremely strange behavior in the console... where the output array appears to be correct until you expand it

enter image description here

Thanks....

Michael C
  • 71
  • 6
  • `results.push(m[1].toString()` is invalid syntax - you're missing a closing parenthesis character `)`. This will throw an error which you've implicitly indicated isn't the actual issue here - please include a [mre] of the *actual code* you're working with. – esqew May 23 '22 at 00:33
  • The problem is not with the regex, but rather with the code that is modifying the `results` array later. Please show your entire, actual code including the `console.log` statements that demonstrates this behaviour as a [mcve]. – Bergi May 23 '22 at 00:34

0 Answers0