replaceAtArrayIndex.tsx 224 B

12345678
  1. /**
  2. * Replace item at `index` in `array` with `obj`
  3. */
  4. export function replaceAtArrayIndex<T>(array: T[], index: number, obj: T): T[] {
  5. const newArray = [...array];
  6. newArray.splice(index, 1, obj);
  7. return newArray;
  8. }