toString() 和 toLocaleString() 的区别

  • toString() 和 toLocaleString() 的区别
区别项 toString() toLocaleString() 结论
new Date() 调用 Tue Apr 17 2018 14:22:34 GMT+0800 (CST) 4/17/2018, 2:23:28 PM
数字:1234 调用 1234 1,234
数组调用 toLocalString()是调用每个数组元素的 toLocaleString() 方法,然后使用地区特定的分隔符把生成的字符串连接起来,形成一个字符串。
  • Object toLocaleString 返回调用 toString() 的结果。
    覆盖 toLocaleString 的对象:
  1. Array:Array.prototype.toLocaleString()
  2. Number:Number.prototype.toLocaleString()
  3. Date:Date.prototype.toLocaleString()
  • 只有覆盖了 toLocaleString 方法的这3个对象,才会返回不一样的结果。
原文地址:https://www.cnblogs.com/cag2050/p/8863184.html