2017-07-12 57 views
-5

試想一下,我有一個嵌套的對象像下面的一個內部對象的名稱:如何獲得一個對象的JavaScript

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

,是有什麼辦法讓對象名稱裏面後,以一個這樣的數組:

["hello", "test"] 
+3

'Object.keys(obj.post)'。 – Tushar

回答

0

試試這個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))

相關問題