let str = "hyt加油!!FIGHTING"
str = str.replace(/[a-zA-Z]/g, content => {
  // => content:每次正则匹配的结果
  // => 1、验证是否为大写字母:把字母转换为大写字母后判断是否和之前一样,如果一样,之前就是大写的;
  // content.toUpperCase()===content
  //    2、在 ASCII 表中找到大写字母的取值范围进行判断(65-90)
  // content.charCodeAt() >= 65 && content.charCodeAt() <= 90
 return content.toUpperCase() === content ? content.toLowerCase() : content.toUpperCase();
})
console.log(str)

相关文章:

  • 2022-01-27
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
相关资源
相似解决方案