我有一个对象数组
对象将采用以下格式
var newUserDetail={"Age":"21","name":"Vicky","UserId":"198303"};
现在我正在尝试比较UserId并替换值
//usersList contains array of newUserDetail kind of objects
jQuery(usersList).each(function(){
if(this.UserId==newUserDetail.UserId){
this=newUserDetail;
}
});
但它会抛出错误
Invalid left-hand side in assignment
答案 0 :(得分:1)
设置数组条目:
jQuery(usersList).each(function (i) {
if (this.UserId == newUserDetail.UserId) {
usersList[i] = newUserDetail;
return false; //if you want to break the loop
}
});
答案 1 :(得分:1)
试试这个
char[]

$(document).ready(function() {
var newUserDetail = {
"Age": "21",
"name": "Vicky",
"UserId": "198303"
};
var tm = {
"Age": "21",
"name": "Vicky",
"UserId": "198303"
};
$.each(newUserDetail, function(k, i) {
if (i == tm.UserId) {
alert("User ID match");
}
})
})