@umbraco-cms/backoffice

    Function pushAtToUniqueArray

    • Function

      pushToUniqueArray

      Type Parameters

      • T

      Parameters

      • data: T[]

        An array of objects.

      • entry: T

        The object to insert or replace with.

      • getUniqueMethod: (entry: T) => unknown

        Method to get the unique value of an entry.

      • index: number

      Returns T[]

      • Returns a new array with the updated entry.
      • Append or replaces an item of an Array.

      Example: Example append new entry for a Array. Where the key is unique and the item will be updated if matched with existing.

      const entry = {key: 'myKey', value: 'myValue'};
      const newDataSet = pushToUniqueArray([], entry, x => x.key === key, 1);
      myState.setValue(newDataSet);
    MMNEPVFCICPMFPCPTTAAATR