Javascript将对象名称提取到数组中

时间:2017-03-29 07:11:38

标签: javascript

如何在JavaScript中获取数组的对象名?

{
    "Ford F-150": [
        {
            "year": 2007,
            "model": "Ford F-150"
        },
        {
            "year": 2007,
            "model": "Ford F-150"
        },
        {
            "year": 2007,
            "model": "Ford F-150"
        }
    ],
    "Toyota Camry": [
        {
            "year": 2011,
            "model": "Toyota Camry"
        }
    ],
    "Dodge RAM": [
        {
            "year": 2005,
            "model": "Dodge RAM"
        }
    ]
}

我希望结果如

var result = ["Ford F-150", "Toyota Camry", "Dodge RAM"]

1 个答案:

答案 0 :(得分:0)

使用此属性访问对象的键

Object.keys(your_obj);