Joj*_*ojo 2 javascript arrays string
function onlyCapitalLetters (str)
{
let newStr = "";
for (let i = 0; i < str.length; i ++) {
if (str[i].includes("ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
newStr += str[i];
}
}
return newStr;
}
onlyCapitalLetters("AMazing"); // should get AM
Run Code Online (Sandbox Code Playgroud)
你好,我正在尝试编写一个函数,它将返回一个仅包含大写字母的新字符串。当我尝试运行此函数时,我没有看到任何输出。请帮忙!!!
实际上,您可能会在这里使用正则表达式方法:
function onlyCapitalLetters (str) {
return str.replace(/[^A-Z]+/g, "");
}
console.log(onlyCapitalLetters("AMazing")); // should get AMRun Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6434 次 |
| 最近记录: |