code: function diffData(oldData, newData) {
      var diffResult = [];
  
      newData.diff(oldData)
          .add(function (idx) {
              diffResult.push({cmd: '+', idx: idx});
          })
          .update(function (newIdx, oldIdx) {
              diffResult.push({cmd: '=', idx: oldIdx, idx1: newIdx});
          })
          .remove(function (idx) {
              diffResult.push({cmd: '-', idx: idx});
          })
          .execute();
  
      return diffResult;
  }
docs: // Assume id in idList are all unique var idIndicesMap = {}; var idx = 0; for (var i = 0; i < newIdList.length; i++) { idIndicesMap[newIdList[i]] = idx; newIdList[i] = idx++; } for (var i = 0; i < oldIdList.length; i++) { var oldId = oldIdList[i]; // Same with newIdList if (idIndicesMap[oldId]) { oldIdList[i] = idIndicesMap[oldId]; } else { oldIdList[i] = idx++; } } }