Search code examples
javascriptv8

Why does the toString() method of an array return an empty string when the array contains a RegExp?


> a = [1, /2/]
[ 1, /2/ ]
> a.toString()
''
> a = [1, 2]
[ 1, 2 ]
> a.toString()
'1,2'

Reproduced on Chrome 104.0.5112.102 and Node v16.17.0. Not sure on other platforms.


Solution

  • Looks like this was reported at crbug.com/v8/13259 a few days before this question was asked, and is being fixed.

    The issue is specific to how the Node and DevTools REPLs are implemented. Inside regular scripts, or with the d8 shell, everything is working as you would expect.