How to list the properties of a JavaScript object?

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

    Since I use underscore.js in almost every project, I would use the keys function:

    var obj = {name: 'gach', hello: 'world'};
    console.log(_.keys(obj));
    

    The output of that will be:

    ['name', 'hello']
    

提交回复
热议问题