Doing a "Diff" on an Associative Array in javascript / jQuery?
Posted
by Matrym
on Stack Overflow
See other posts from Stack Overflow
or by Matrym
Published on 2010-04-01T07:28:40Z
Indexed on
2010/04/01
7:33 UTC
Read the original article
Hit count: 360
If I have two associative arrays, what would be the most efficient way of doing a diff against their values?
For example, given:
array1 = {
foreground: 'red',
shape: 'circle',
background: 'yellow'
};
array2 = {
foreground: 'red',
shape: 'square',
angle: '90',
background: 'yellow'
};
How would I check one against the other, such that the items missing or additional are the resulting array. In this case, if I wanted to compare array1 within array2, it would return:
array3 = {shape: 'circle'}
Whilst if I compared array2 within array1, it would return:
array3 = {shape: 'square', angle: '90'}
Thanks in advance for your help!
© Stack Overflow or respective owner