试想一下,我有一个像下面这样的嵌套对象:
{
"post":{
"hello":{
// what's in here doesn't matter
}
"test":{
// also doesn't matter
}
}
有什么方法可以将 post 中的对象名称获取到这样的数组中:
["hello", "test"]
试试这个 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))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句