w2olves
w2olves

Reputation: 2329

Detecting changes in a Javascript array using observe but not comparing to another array

I can detect changes in a javascript array by using Array.observe.

Like this:

Array.observe(myArray, function (changes) {
            // handle changes... in this case, we'll just log them 
            changes.forEach(function (change) {
                console.log(change.object);
             });

However I am not able to find an easy way of getting just the changed element (considering elements were added).

Is there a way to detect what was added without comparing this array to a copy of the original array ?

Upvotes: 0

Views: 293

Answers (1)

faron
faron

Reputation: 1059

Accourding to documentation you can get this info from the data passed into the callback.

Also please pay attention that Array.observe is obsolete and consider using Proxy instead

Upvotes: 1

Related Questions