showing results for - "jquery to json diff"
Karl
01 Jan 2021
1function diff(obj1, obj2) {
2    const result = {};
3    if (Object.is(obj1, obj2)) {
4        return undefined;
5    }
6    if (!obj2 || typeof obj2 !== 'object') {
7        return obj2;
8    }
9    Object.keys(obj1 || {}).concat(Object.keys(obj2 || {})).forEach(key => {
10        if(obj2[key] !== obj1[key] && !Object.is(obj1[key], obj2[key])) {
11            result[key] = obj2[key];
12        }
13        if(typeof obj2[key] === 'object' && typeof obj1[key] === 'object') {
14            const value = diff(obj1[key], obj2[key]);
15            if (value !== undefined) {
16                result[key] = value;
17            }
18        }
19    });
20    return result;
21}
queries leading to this page
jquery to json diffjquery to json diff