Get object property name as a string

后端 未结 13 567
难免孤独
难免孤独 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条回答
  •  Happy的楠姐
    2020-12-04 19:20

    I know a best practice that using Object.keys(your_object). It will parse to array property name for you. Example:

    var person = { firstName: 'John', lastName: 'Cena', age: '30' };
    var listPropertyNames = Object.keys(person); //["firstName", "lastName", "age"]
    

    I hope this example is useful for you.

提交回复
热议问题