本文介绍了将数组转换为大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数组,我想改成大写,但我不能让它工作。请帮我。
I have an array that I want to change to upper case but I can´t make it work. Please help me.
var array2 = ["melon","banana","apple","orange","lemon"];
array2.toUpperCase()
我也试过以下但是它不起作用。
I have also tried the below but it doesn´t work neither.
array2.map(toUpperCase);
提前致谢!
推荐答案
你应该在地图中使用处理函数:
you should use handler function in map:
var array2 = ["melon","banana","apple","orange","lemon"];
array2 = array2.map(function(x){ return x.toUpperCase() })
编辑:是的,你可以做到
edit: yes you can do
toUpper = function(x){
return x.toUpperCase();
};
array2 = array2.map(toUpper);
这篇关于将数组转换为大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!