给定下面的对象数组:

function person(first, last, RPI, o, t, u) {
    this.first = first;
    this.last = last;
    this.RPI =  RPI;
    this.o = o;
    this.t = t;
    this.u = u;
}

var MD = new person('Mike', 'D', 1234, '', '', '');
var AY = new person('Adam', 'Y', 5678, '', '', '');
var AH = new person('Adam', 'H', 1212, '', '', '');

var personArray = new Array(MD, AY, AH);


如何将每个对象的RPI值迭代到此公式中?

function selector(x){
//do something with x.RPI
}


我试过了:

$.each(personArray , selector (personArray[person].RPI){
selector(x)
});


但这是行不通的。我的每句话都错在哪里?

最佳答案

$.each回调必须是一个函数
执行以下操作:

var personArray = new Array (MW, MT, DR)
$.each(personArray, function(index, person){
   console.log(person.RPI);
}

关于javascript - 使用$ .each遍历对象数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41581880/

10-09 18:14
查看更多