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?
-
Meant to say replace the date value into some other valueKalaivani– Kalaivani2012年02月08日 06:50:19 +00:00Commented Feb 8, 2012 at 6:50
2 Answers 2
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
}
});
Comments
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.