Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array - join and toString calls return an empty string after toLocaleString call

I'm not getting the point why calls to the join and toString methods on an Array object return an empty string after a call to toLocaleString:

let A = [1, 2, 3];
A.toString(); => "1,2,3"
A.join(); => "1,2,3"
A => (3) [1, 2, 3]
A.toLocaleString(); => ""
A.toString(); => ""
A.join(); => ""
A => (3) [1, 2, 3]

I'm trying on Google Chrome 73.0.3683.103, on Firefox I don't experience the same issue.

like image 297
zer0uno Avatar asked Nov 06 '22 18:11

zer0uno


1 Answers

This is a bug

To fix this issue, you can use this way:

[...A].toLocaleString();

//or

[].concat(A).toLocaleString();
like image 119
Behnam Mohammadi Avatar answered Nov 15 '22 08:11

Behnam Mohammadi