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!
To convert all array elements to lowercase:Use the map() method to iterate over the array. On each iteration, call the toLowerCase() method to convert the string to lowercase and return the result. The map method will return a new array containing only lowercase strings.
Convert all the elements in each and every word in to lowercase using string. toLowerCase() method. Loop through first elements of all the words using for loop and convert them in to uppercase.
The toUpperCase() method converts a string to uppercase letters. The toUpperCase() method does not change the original string.
Java String toUpperCase() Method The toUpperCase() method converts a string to upper case letters.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With