Javascript foreach loop on associative array object

后端 未结 9 964
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 04:41

Why my for for-each loop is not iterating over my JavaScript associative array object?

// defining an array
var array = [];

// assigning values to correspon         


        
9条回答
  •  眼角桃花
    2020-12-02 05:24

    var obj = {
      no: ["no", 32],
      nt: ["no", 32],
      nf: ["no", 32, 90]
    };
    
    count = -1; // which must be static value
    for (i in obj) {
      count++;
      if (obj.hasOwnProperty(i)) {
        console.log(obj[i][count])
      };
    };

    in this code i used brackets method for call values in array because it contained array , however briefly the idea which a variable i has a key of property and with a loop called both values of associate array

    perfect Method , if you interested, press like

提交回复
热议问题