【问题标题】:how to move to the next string's character in java Script?如何在javascript中移动到下一个字符串的字符?
【发布时间】:2022-06-13 21:33:56
【问题描述】:

我必须在 JavaScript 中制作缩写功能,但无论我做什么,我都找不到将诸如“美国国家航空航天局”之类的短语缩写为 NASA 的方法。我只能返回N。 这是我写的代码:

function makeAbbr(words) {
 let abbreviation = words.trim();
 for (let i=0; i< words.length; i++){
  if(words[i]!==''){
   return abbreviation.toUpperCase().charAt(0);
 }if(words[i]===''){
   abbreviation+= words.charAt();
 }
}
}

【问题讨论】:

    标签: javascript abbreviation


    【解决方案1】:

    尝试给一个空格而不是空字符串

    words[i]!==' '
    

    将此应用于其他部分

    【讨论】:

      猜你喜欢
      • 2021-09-19
      • 1970-01-01
      • 1970-01-01
      • 2016-08-16
      • 1970-01-01
      • 2019-06-26
      • 2022-11-20
      • 2013-12-13
      • 2020-07-01
      相关资源
      最近更新 更多