How to get the object's name inside a object javascript

时间:2017-07-12 08:15:39

标签: javascript arrays object

Just imagine I have a nested object like the following one:

{
    "post":{
        "hello":{
            // what's in here doesn't matter
        }
        "test":{
            // also doesn't matter
        }
}

and is there any way to get the object name inside post to an array like this:

["hello", "test"]

1 个答案:

答案 0 :(得分:0)

Try this Object.keys(a.post)

var a = {
    "post": {
      "hello": {
        // what's in here doesn't matter
      },
      "test": {
        // also doesn't matter
      },
    }
}
    console.log(Object.keys(a.post))