如何遍历以对象为成员的纯JavaScript对象?

删除回忆录丶 提交于 2020-08-13 08:31:23

问题:

How can I loop through all members in a JavaScript object including values that are objects. 如何遍历JavaScript对象中的所有成员,包括对象值。

For example, how could I loop through this (accessing the "your_name" and "your_message" for each)? 例如,如何循环浏览(分别访问“ your_name”和“ your_message”)?

var validation_messages = {
    "key_1": {
        "your_name": "jimmy",
        "your_msg": "hello world"
    },
    "key_2": {
        "your_name": "billy",
        "your_msg": "foo equals bar"
    }
}

解决方案:

参考一: https://stackoom.com/question/3rnZ/如何遍历以对象为成员的纯JavaScript对象
参考二: https://oldbug.net/q/3rnZ/How-to-loop-through-a-plain-JavaScript-object-with-the-objects-as-members
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!