I\'m interested if there is any function like array_map or array_walk from php.
Don\'t need an for that travels all the array. I can do that for myself.
This may be an overkill but you can also do
var upperCaseArray = array.map(String.prototype.toUpperCase.call.bind(String.prototype.toUpperCase));
Similar to a previous for loop answer, this one uses some of the more basic features of javascript:
function looptoUpper(arr){
var newArr = [];
for (var i = 0; i < arr.length; i++){
newArr.push(arr[i].toUpperCase());
}
return newArr;
}
looptoUpper(['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab']);
Javascript has a map() method. A good reference is at http://www.tutorialspoint.com/javascript/array_map.htm
And here is the one-liner without creating a loop or a function that is ES3 compatible It's alos faster since you only call toUpperCase once
// watch out for strings with comma (eg: ["hi, max"]) then use custom join/split()
// or just use something safer such as Array.map()
var uppercaseArray = array.toString().toUpperCase().split(",");
var uppercaseArray = array.join(0).toUpperCase().split(0);
var uppercaseArray = (array+"").toUpperCase().split(",");