This question already has answers here:
Javascript - Making Array Index toLowerCase() not working
                                
                                    (3个答案)
                                
                        
                2年前关闭。
            
        

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



var title = 'The Quick brown fox';

var titleCase = [];


var Titlewords = title.split("");

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

    console.log(Titlewords[i]);

}

最佳答案

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



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]);

}

09-20 14:47