简体   繁体   English

如何访问javascript数组包含对象中的responsedata

[英]how to access responsedata in javascript array contains object

In javascript array, contains value (ie; type is object). 在javascript数组中,包含值(即,类型为object)。 that object contains another array of values. 该对象包含另一个值数组。 Inside this Array had 3 objects. 该数组内部有3个对象。 And the object there are some variables. 而且对象有一些变量。 how to push one variable to another array in javascript 如何在JavaScript中将一个变量推送到另一个数组

var studentData = new Array();

success: function(responseData) {
    $.each(responseData, function(index, item) { 
        studentData.push(responseData.markMasterList(0).markMasterDetails(i).student.name);

responseData shows .. responseData显示..

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

I tried with this one but got error on console 我尝试了这个但控制台出现错误

studentData.push(responseData.markMasterList(0).markMasterDetails(i).student.name);

error shows: 错误显示:

Uncaught TypeError: object is not a function 未捕获的TypeError:对象不是函数

Without more snippets, I can only gues, but You might have missed the array syntax. 没有更多的摘要,我只能猜测,但是您可能会错过数组语法。

You need [ ] to refer to an array ( /object ) key, not ( ) 您需要[]来引用数组(/ object)键,而不是()

studentData.push(responseData.markMasterList[0].markMasterDetails[i].student.name);

( I know, your question was referring to objects, but in JS, arrays and objects have a lot in common. Fe: ) (我知道,您的问题是指向对象的,但是在JS中,数组和对象有很多共同点。Fe:)

var a = { 1 : "a" , 2 : "b" };
a[ 1 ] // Gives "a"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM