function InsertUpdateArray(arr, newItem, keyProperty) {

  let updated = false;

  const newArr = arr.map(item => {

    if (item[keyProperty] === newItem[keyProperty]) {

      updated = true;

      return { ...item, ...newItem }; // Merge new item properties with existing

    }

    return item;

  });



  if (!updated) {

    newArr.push(newItem); // Add new item if not found

  }

  return newArr;

}