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

后端 未结 8 917
后悔当初
后悔当初 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);
    });

    0 讨论(0)
  • 2021-02-01 12:59

    Use the built-in Javascript function called map. .map() will do the exact thing you're looking for!

    0 讨论(0)
提交回复
热议问题