3

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?

1
  • Meant to say replace the date value into some other value Commented Feb 8, 2012 at 6:50

2 Answers 2

3

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
  }
});
Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

var user = arrData[index]; user.Value = newValue; arrData[index] = user;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.