如何从嵌套数组中获取数据

时间:2017-08-27 15:29:31

标签: javascript arrays

Array
(
    [0] => Array
        (
            [id] => 1
            [main_categories] => MCAT
            [sucategory] => Chemistry
        )

    [1] => Array
        (
            [id] => 2
            [main_categories] => MCAT
            [sucategory] => Physics
        )

    [2] => Array
        (
            [id] => 3
            [main_categories] => MCAT
            [sucategory] => Biology
        )

)

我想获得idmain_categoriessubcategory。 我使用data[0]只返回A

1 个答案:

答案 0 :(得分:1)

let data = [

    {
        id: 1,
        main_categories: "MCAT",
        sucategory: "Chemistry"
    },

    {
        id: 2,
        main_categories: "MCAT",
        sucategory: "Physics"
    },

    {
        id: 3,
        main_categories: "MCAT",
        sucategory: "Biology"
    }

];

console.log(data[0])