I have a strange issue, which I don't understand.
At this point I set a php array as a jquery variable and call myFunction with chatData as parameter:
var chatData = JSON.parse('<? echo json_encode($chatData); ?>');
myFunction(chatData)
function myFunction(chatData) {
  console.log("ORIGINAL")
  console.log(chatData)
  $.ajax({
    type: "POST",
    url: "getData.php",
    data: 'chatData=' + JSON.stringify(chatData),
    dataType: 'json',
  }).done(function(result) {
    if (result.length > 0) {
      for (var i = 0; i < result.length; i++) {
        console.log("SEARCH " + result[i].chatToken)
        for (var x = 0; x < chatData.length; x++) {
          for (key in chatData[x]) {
            if (chatData[x].chatToken.indexOf(result[i].chatToken) != -1) {
              //chatData[x].lastMessageID = 999
              console.log("FOUND  " + chatData[x].chatToken);
            }
          }
        }
        console.log("ChatData AFTER UPDATE")
        console.log(chatData)
      }
    }
  })
};
This function will do some stuff and the console log Output will be this:

All ok ! As you see, I exclude the following line:
chatData[x].lastMessageID = 999
This line should change the value of lastMessageID to 999, after ajax is done. Now: I run the code again with this line and the output shows like this:
lastMessageID has the Number 999 - perfect! What I don't understand: Why has chatData this new value at the beginning ("START"). I change this value the first time in the "ajax done part" - nowhere before.
Do you have an idea?

 
    