0

I have an array which is being used to store multiple rows. Now on some event I update the value of rows based on Id. eg. if a used makes changes to one of the text box I want to update my array with latest value. This update has to be done at "onblur" event of textbox. If the value is updated I am inserting it into another array called arrActionData which records all the updates.

However, if I do not make any changes and I want to check whether the value of array has changed or not. Is there a way to do so? I want to figure out a way to prevent myself from inserting records in array which do not have update.

Gaurav Sachdeva
  • 75
  • 2
  • 3
  • 9
  • 1
    Any code that you have tried ? – Varun Jun 24 '15 at 14:58
  • possible duplicate of http://stackoverflow.com/questions/7837456/comparing-two-arrays-in-javascript – Himanshu Tanwar Jun 24 '15 at 15:07
  • Are you opposed to third party libraries, such as [KnockoutJS](http://knockoutjs.com/)? If not, they have done all of the work, you can create a ViewModel (JS object) and pass your array to create an observableArray in and use a function that will fire whenever the observableArray changes. – JasonWilczak Jun 24 '15 at 15:08

1 Answers1

0

The trivial way to do this is to keep the original array for reference.
Then you can iterate over both arrays and compare the values, for example like this:
Assuming your arrays are originalArrayand newArray:

foreach (originalArray AS key => value) {
  if (newArray['key'] != originalArray['key']) {
    alert (key + 'was changed');
  }
}
Burki
  • 1,188
  • 19
  • 28