如何遍歷對象內部的對象

西倫特

服務器給出以下響應:

SomeObject:{
    Object1:{
        id: 123456789,
        name: "Foo"
    },
    Object2:{
        id: 123456789,
        name: "Bar"
    }
}

是否有可能遍歷SomeObject和顯示兩個idnameObject1/Object2搜索這個主要導致使用Object.keys(SomeObject).map但是這些用於獲取Object1/Object2.

馬吉德·巴達維

const SomeObject = { Object1: { id: 123456789, name: "Foo" }, Object2:{ id: 123456789, name: "Bar" } };

const res = 
  Object.values(SomeObject)
  .forEach(({ id, name }) => console.log(id, name));

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章