在 javascript 数组中,包含值(即;类型是对象)。该对象包含另一个值数组。这个数组里面有 3 个对象。而且对象还有一些变量。如何在 JavaScript 中将一个变量推送到另一个数组
var studentData = new Array();
success: function(responseData) {
$.each(responseData, function(index, item) {
studentData.push(responseData.markMasterList(0).markMasterDetails(i).student.name);
响应数据显示..
Array[5]
>0: Object
>markArray: Array[1]
>0: Object
>markDetailsArray: Array[10]
>0: Object
>student: Object
>name //How to push this variable to studentData
>1: Object
>2: Object
>3: Object
>1: Object
我尝试过这个,但在控制台上出现错误
studentData.push(responseData.markMasterList(0).markMasterDetails(i).student.name);
错误显示:
Uncaught TypeError: object is not a function
最佳答案
如果没有更多代码片段,我只能猜测,但您可能错过了数组语法。
您需要 [ ] 来引用数组 (/object ) 键,而不是 ( )
studentData.push(responseData.markMasterList[0].markMasterDetails[i].student.name);
(我知道,你的问题是指对象,但在 JS 中,数组和对象有很多共同点。F.e: )
var a = { 1 : "a" , 2 : "b" };
a[ 1 ] // Gives "a"
关于javascript - 如何访问javascript数组包含对象中的responsedata,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28062012/