jquery - Javascript Best Practice for finding all differing Nested Array Elements -


with 2 large, potentially large nested javascript arrays. 1 current , other previous iteration of array. function need find differing elements , act upon changed.

i know how make function this, wondering best practices doing such thing. advice appreciated. looking @ using either native javascript jquery handling responses differing elements.

this question deals several things.

  1. what most efficient way compare objects. in javascript checking, via if, if object equals or not equal object, not, if equal. objects need broken down , compared.

  2. what best way return results? make array of differences? while going though first array clear out objects same in first, or make entirely new array return?

function comparearrays(arr1, arr2){         for(var key in arr1){         if( arr1[key] !== arr2[key]){             // traverse nested array             if(typeof(arr1[key]) == 'object' || typeof(arr2[key]) == 'object'){                                 comparearrays( arr1[key], arr2[key]);             }         }else{                 delete arr2[key];         }     } }  var a1 = [1,2,3,["a","b","c"],4,5,6,["d","e","f"]]; var a2 = [1,2,5445,["a","tt","c"],4,5,336,["d","edee","ffdf"], 'blablabla', 'i\'m extra'];  comparearrays( a1, a2 ); console.log(a2); 

this @ second given. , modify removing shared equal values. array still intact values same undefined.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -