In nodeJs is there a way to loop through an array without using array size?

后端 未结 8 921
后悔当初
后悔当初 2021-02-01 11:56

Let\'s say I have

myArray = [\'item1\', \'item2\']

I tried

for (var item in myArray) {console.log(item)}

It

8条回答
  •  清歌不尽
    2021-02-01 12:55

    To print 'item1' , 'item2', this code would work.

    var myarray = ['hello', ' hello again'];
    
    for (var item in myarray) {
        console.log(myarray[item])
    }
    

提交回复
热议问题