创建所有大写字母的饮料数组
var drinks = ["Coke", "Pepsi", "Water", "Orange Juice"];
console.log("First statement");
console.log(drinks[0]);
console.log(drinks[1]);
console.log(drinks[2]);
console.log(drinks[3]);
然后(分别)修改数组的每个元素以使其小写
最佳答案
如下所示使用.map()
。这基本上遍历了数组中的每个元素,并使用.toLowerCase()
将字符串更改为小写字符串。
var drinks = ["Coke", "Pepsi", "Water", "Orange Juice"];
var lowerCaseDrinks = drinks.map(e => e.toLowerCase());
console.log(lowerCaseDrinks);