Finding the differences between two revisions (or objects)
You certainly seem to be going a pretty long detour in some cases.

What worries me most is that you look at stringified JSON. Just look at the objects. If you try to manually parse JSON by splitting on commas, you risk splitting on commas in strings, and all sorts of other nonsense. 

You really don't need raw JSON strings for anything here (except perhaps for printing the result in a readable way)

Just iterate the objects with for...in, and use hasOwnProperty to check for properties.

For instance:



var A = {A: 10, B: 20, C: 30, D: 90, BB: 5, CC: 4, AA: 2};
var B = { B: 22, C: 30, L: 4, KK: 444, A:15};

var difference = diff(A, B);
document.write("&lt;pre&gt;"+JSON.stringify(difference, 0, 3)+"&lt;/pre&gt;");

function diff(a, b) {
  var result = {
    removed: {},
    changed: {},
    created: {},
    notChanged: {}
  };
    
  // check for changed/unchanged/removed keys
  for(var aKey in a) {
    if(!a.hasOwnProperty(aKey)) continue; // skip inherited properties
    
    if(b.hasOwnProperty(aKey)) {
      // check for changed/unchanged values
      if(b[aKey] === a[aKey]) {
        result.notChanged[aKey] = a[aKey]; // no change between a and b
      } else {
        result.changed[aKey] = [a[aKey], b[aKey]]; // get before/after values
      }
    } else {
      result.removed[aKey] = a[aKey]; // key wasn't in b, so it's been removed
    }
  }
  
  // do the reverse to check for added keys
  for(var bKey in a) {
    if(!b.hasOwnProperty(bKey)) continue;
    if(!a.hasOwnProperty(bKey)) {
      result.created[bKey] = b[bKey];
    }
  }
       
  return result;
}