How to list the properties of a JavaScript object?

后端 未结 17 2580
刺人心
刺人心 2020-11-22 00:34

Say I create an object thus:

var myObject =
        {\"ircEvent\": \"PRIVMSG\", \"method\": \"newURI\", \"regex\": \"^http://.*\"};

What is

17条回答
  •  温柔的废话
    2020-11-22 01:13

    Use Reflect.ownKeys()

    var obj = {a: 1, b: 2, c: 3};
    Reflect.ownKeys(obj) // ["a", "b", "c"]
    

    Object.keys and Object.getOwnPropertyNames cannot get non-enumerable properties. It's working even for non-enumerable properties.

    var obj = {a: 1, b: 2, c: 3};
    obj[Symbol()] = 4;
    Reflect.ownKeys(obj) // ["a", "b", "c", Symbol()]
    

提交回复
热议问题