how to map an array with uppercase function in javascript?

前端 未结 10 1285
野趣味
野趣味 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条回答
  •  猫巷女王i
    2021-02-12 20:23

    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(",");
    

提交回复
热议问题