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

后端 未结 8 912
后悔当初
后悔当初 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:59

    You can use Array.forEach

    var myArray = ['1','2',3,4]
    
    myArray.forEach(function(value){
      console.log(value);
    });

提交回复
热议问题