Reputation: 485
I have array object in jquery.
array=[];
array{Id:user.Id,Date:user.Date};
Now am going to pass this array object to my handler file which have n number of users. In success function now am going to change the Date for the array only for the particular user. For that i have to find whether array has the user, if yes i have to change the date. So,
if (jQuery.inArray(user.Id, array)) {
// code have to done
}
If my above code is right, Can anyone tell me how to change the date value of the user or tell me any-other simplified way?
Upvotes: 3
Views: 4423
Reputation: 31467
jQuery.inArray()
won't find the item in this way.
I recommend to use jQuery.each()
instead, because unfortunately jQuery does not provide a find
function for arrays.
jQuery.each(array, function(index, data) {
if (data.Id === user.Id) {
data.Date = newDate;
return false; // this stops the each
}
});
Upvotes: 3
Reputation: 6353
Using this method: jQuery.inArray("Q", arrData);
You can get the index of you object in array. After that get the object from index and update it.
Upvotes: 0