简体   繁体   中英

browsing throwing error replaceAll is not a function

I'm getting this error on chrome 84 somehow still not sure if it's the replaceAll method that is the problem or the function

Intl.DateTimeFormat(...) .resolvedOptions(...) .timeZone.replaceAll is not a function

function GetHumanTimezone() {
  return Intl.DateTimeFormat().resolvedOptions().timeZone.replaceAll('_', '-');
}

Replaceall is useless in my opinion. Just do .timeZone.replace(/_/g, '-');

but if you insist:

For your ancient Chrome you can do

 if (!"".replaceAll) String.prototype.replaceAll = function(search, replacement) { var target = this; return target.replace(new RegExp(search, 'g'), replacement); }; console.log(Intl.DateTimeFormat().resolvedOptions().timeZone.replaceAll("_", "-"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM