Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
-5
rated 0 times [  1] [ 6]  / answers: 1 / hits: 111378  / 9 Years ago, sat, april 18, 2015, 12:00:00

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


Thanks in advance!


More From » arrays

 Answers
12

you should use handler function in map:


var array2 = ["melon","banana","apple","orange","lemon"];
array2 = array2.map(function(x){ return x.toUpperCase(); })

for more information about map


edit: yes you can do


toUpper = function(x){ 
return x.toUpperCase();
};
array2 = array2.map(toUpper);

[#67018] Thursday, April 16, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leslijessalyng

Total Points: 650
Total Questions: 85
Total Answers: 109

Location: Croatia
Member since Mon, Sep 6, 2021
3 Years ago
leslijessalyng questions
Fri, Feb 21, 20, 00:00, 4 Years ago
Tue, Jul 30, 19, 00:00, 5 Years ago
Fri, Jul 5, 19, 00:00, 5 Years ago
Wed, Mar 13, 19, 00:00, 5 Years ago
;