如何将拆分单词转换为小写

时间:2017-09-03 10:12:58

标签: javascript

如何将我分成小写的单词转换成?我有以下代码。



/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"




4 个答案:

答案 0 :(得分:2)

你可以在JavaScript中做很多事情而不需要自己编写循环。这只是另一个例子。

const title = 'The Quick brown fox';
const words = title.split(' ').map(word => word.toLowerCase());

// print the array
console.log(words);

// print the single words
words.forEach(word => console.log(word));

<强>资源

答案 1 :(得分:1)

您只需将Titlewords[i].toLowerCase()分配回Titlewords[i]

即可

&#13;
&#13;
var title = 'The Quick brown fox';

var titleCase = [];


var Titlewords = title.split("");

for (var i = 0; i < Titlewords.length; i++) {
Titlewords[i] = Titlewords[i].toLowerCase();

console.log(Titlewords[i]);

}
&#13;
&#13;
&#13;

答案 2 :(得分:0)

您需要更新值

Titlewords[i] = Titlewords[i].toLowerCase();

&#13;
&#13;
var title = 'The Quick brown fox';

var titleCase = [];


var Titlewords = title.split("");

for (var i = 0; i < Titlewords.length; i++) {
    Titlewords[i] = Titlewords[i].toLowerCase();

    console.log(Titlewords[i]);

}
&#13;
&#13;
&#13;

答案 3 :(得分:0)

str.toLowerCase()返回一个字符串,而不是将其设置为更低。你想要做的是

Titlewords[i] = Titlewords[i].toLowerCase();