Get object property name as a string

后端 未结 13 589
难免孤独
难免孤独 2020-12-04 18:40

Is it possible to get the object property name as a string

person = {};
person.first_name = \'Jack\';
person.last_name = \'Trades\';
person.address = {};
per         


        
13条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 19:32

    I prefer it clean and simple like this:

    var obj = {
      sessionId: 123,
      branchId: 456,
      seasonId: 789
    };
    
    var keys = Object.keys(obj);
    
    for (var i in keys) {
      console.log(keys[i]); //output of keys as string
    }
    

提交回复
热议问题