How to list the properties of a JavaScript object?

后端 未结 17 2572
刺人心
刺人心 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:27

    With ES6 and later (ECMAScript 2015), you can get all properties like this:

    let keys = Object.keys(myObject);
    

    And if you wanna list out all values:

    let values = Object.keys(myObject).map(key => myObject[key]);
    

提交回复
热议问题