Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法将元素推送到数组中_Javascript_Arrays_Ionic2 - Fatal编程技术网

Javascript 无法将元素推送到数组中

Javascript 无法将元素推送到数组中,javascript,arrays,ionic2,Javascript,Arrays,Ionic2,我试图将元素推送到名为“toServiceSubCatNamesList”的数组的末尾 “loadServiceTypes”数组的结构为: { "serviceTypes": [ { "service_type_id": 1, "service_type_name": "Cutting", "service_type_price": "3000.00", "created_at": null, "update

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

“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 > 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)
“ToServiceSubcatNameList”数组的结构为:

{
"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 > 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\u type\u name'。任何克服这个问题的建议

如何以及在何处访问数组
toServiceSubCatNamesList
?this.toServiceSubCatNamesList.push(this.loadServiceTypes.serviceTypes[j]);它是一个对象,不是数组。您将需要类似于this.toServiceSubCatNamesList[j]=this.loadServiceTypes.ser的内容‌​邻位[j]我认为这个错误不是由推送函数引起的。在您的文件中搜索您在哪里使用
服务\u键入\u名称
,并检查itI是否同意@duanx。在代码中的某个地方,您试图访问未定义对象上的属性
service\u type\u name
。如何以及在何处访问数组
toServiceSubcatNameList
?this.toServiceSubcatNameList.push(this.loadServiceTypes.serviceTypes[j]);它是一个对象,不是数组。您将需要类似于this.toServiceSubCatNamesList[j]=this.loadServiceTypes.ser的内容‌​邻位[j]我认为这个错误不是由推送函数引起的。在您的文件中搜索您在哪里使用
服务\u键入\u名称
,并检查itI是否同意@duanx。在代码中的某个地方,您试图访问未定义对象上的属性
服务\u type\u name