You could simplify the JSONata to
$append($flowContext("array")[$ != $$.payload], [$$.payload])
this wiill return the context array minus the incoming payload, then append the new payload to the end of the array, this also works well for arrays of objects.
this thread has some good examples of searching and appending to arrays with JSONata