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

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

        var count=0;
        let myArray = '{"1":"a","2":"b","3":"c","4":"d"}'
        var data = JSON.parse(myArray);
        for (let key in data) {
          let value =  data[key]; // get the value by key
          console.log("key: , value:", key, value);
          count = count + 1;
        }
       console.log("size:",count);
    

提交回复
热议问题