到目前为止,我已经完成了数组的设置,我只需要如何选择所说的4个字符以内或更少的单词的指导。谢谢!

function processString(someInput) {
            var someArray = someInput.split(" ");
            var newCSVString = "";
            for (var x = 0; x < someArray.length; x++) {
                newCSVString.push(someArray[x].charAt(3).toUpperCase() + someArray[x].toLowerCase());

最佳答案

根据我对您的问题和评论的理解,我认为您正在寻找String.replace



function processString(string) {
  return string.replace(/\w+/g, word =>
    word.length < 4 ? word.toUpperCase() : word.toLowerCase()
  );
}

// Example:
console.log(processString("a abc abcd abcde")); // A ABC abcd abcde

关于javascript - 解决方法是将JavaScript中的以下字符串转换为大写4个字母或更少,小写4个字母或更多的字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44036537/

10-12 03:15