@umbraco-cms/backoffice
    Preparing search index...

    Function replaceInUniqueArray

    • Function

      replaceInUniqueArray

      Type Parameters

      • T

      Parameters

      • data: T[]

        An array of objects.

      • entry: T

        The object to replace with.

      • getUniqueMethod: (entry: T) => unknown

        Method to get the unique value of an entry.

      Returns T[]

      • Replaces an item of an Array.

      Example: Example replace an entry of an Array. Where the key is unique and the item will only be replaced if matched with existing.

      const data = [{key: 'myKey', value:'initialValue'}];
      const entry = {key: 'myKey', value: 'replacedValue'};
      const newDataSet = replaceInUniqueArray(data, entry, x => x.key === key);