Javascript 无法将元素推送到数组中
我试图将元素推送到名为“toServiceSubCatNamesList”的数组的末尾 “loadServiceTypes”数组的结构为: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
{
"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
。