无法将元素推送到数组

时间:2017-06-30 07:01:37

标签: javascript arrays ionic2

我试图将元素推送到数组的末尾,名为" toServiceSubCatNamesList"

this.toServiceSubCatNamesList.push(this.loadServiceTypes.serviceTypes[j]);

" loadServiceTypes"的结构数组是:

{
"serviceTypes": [
    {
        "service_type_id": 1,
        "service_type_name": "Cutting",
        "service_type_price": "3000.00",
        "created_at": null,
        "updated_at": null,
        "pivot": {
            "service_service_type_service_id": 1,
            "service_service_type_service_type_id": 1
        }
    }
  ]
}

" toServiceSubCatNamesList"的结构数组是:

toServiceSubCatNamesList > 0:Object
                                 created_at:null
                                 pivot:Object
                                 service_type_id:1
                                 service_type_name:"Washing"
                                 service_type_price:"3000.00"
                                 updated_at:null
                                 __proto__:Object
                                 length:1
                                 __proto__:Array(0)

当我这样做时,它会给出错误" TypeError:无法读取属性' service_type_name'未定义"。有任何建议可以克服这个问题!

0 个答案:

没有答案