Traverse through Javascript object properties

前端 未结 8 1687
清酒与你
清酒与你 2021-01-31 01:48

I want to traverse through JavaScript object\'s property

    var obj =
    {
        a: \'value1\',
        b: \'value2\',
        c: \'value3\',
        d: \'va         


        
8条回答
  •  深忆病人
    2021-01-31 02:10

    Using ecmascript2017: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries

    const object1 = {
      a: 'somestring',
      b: 42
    };
    
    for (let [key, value] of Object.entries(object1)) {
      console.log(`${key}: ${value}`);
    }
    

提交回复
热议问题