📌  相关文章
📜  循环遍历嵌套的 json 对象 typescript - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:28.148000             🧑  作者: Mango

代码示例1
var catalog = 
{
    "products": [
        {
            "name": "prod 1",
            "versions": [
                "ver 1",
                "ver 2"
            ]
        },
        {
            "name": "prod 2",
            "versions": [
                "ver 1",
                "ver 2"
            ]
        }
    ]
};

for(var i = 0; i < catalog.products.length; i++)
{
    var product = catalog.products[i];
    var productName = product.name;
    for(var j = 0; j < product.versions.length; j++)
    {
        var version = product.versions[j];
    }
}