how to map an array with uppercase function in javascript?

前端 未结 10 1428
野趣味
野趣味 2021-02-12 19:29

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.



        
10条回答
  •  半阙折子戏
    2021-02-12 20:10

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

提交回复
热议问题