myArray[items].toUpperCase is not a function

This question already has an answer here:

  • Why is using “for…in” with array iteration a bad idea? 25 answers

  • I'm not sure this will guarantee the order of the elements in the array. The best solution would be to go with a for loop (both for performance and order):

    for (var i=0, len=myArray.length; i<len; i++){
          msgupdate += myArray[i].toUpperCase()+' ';
    }
    

    Use

    msgupdate = myArray.map(function (i) { return i.toUpperCase() }).join(' ');
    

    Using for/in isn't a good idea, without a hasOwnProperty check.

    链接地址: http://www.djcxy.com/p/70028.html

    上一篇: 从复杂的json对象创建javascript数组

    下一篇: myArray [items] .toUpperCase不是函数