Se ho due array associativi, quale sarebbe il modo più efficiente di fare una diff contro i loro valori?Fare una "Diff" su una matrice associativa in javascript/jQuery?
Ad esempio, dato:
array1 = {
foreground: 'red',
shape: 'circle',
background: 'yellow'
};
array2 = {
foreground: 'red',
shape: 'square',
angle: '90',
background: 'yellow'
};
Come dovrei controllare uno contro l'altro, in modo tale che gli articoli mancanti oulteriori sono la matrice risultante. In questo caso, se volevo confrontare array1 all'interno array2, che sarebbe tornato:
array3 = {shape: 'circle'}
Mentre se ho confrontato array2 all'interno array1, che sarebbe tornato:
array3 = {shape: 'square', angle: '90'}
Grazie in anticipo per il vostro aiuto!