1. If store uses a , then:

      1. If key is undefined, then:

        1. Let key be the result of running the steps to generate a key for store.

        2. If key is failure, then this operation failed with a ““ [DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException). Abort this algorithm without taking any further steps.

        3. If store also uses , then run the steps to inject a key into a value using a key path with value, key and store’s .

    2. If a record already exists in store with its key key, then remove the record from store using the steps to .

    3. Store a record in store containing key as its key and ! (value) as its value. The record is stored in the object store’s list of records such that the list is sorted according to the key of the records in order.

    4. For each index which reference store:

      1. Let index key be the result of running the steps to with value, index’s key path, and index’s .

      2. If index’s multiEntry flag is set and index key is an , and if index already contains a record with equal to any of the of index key, and index has its unique flag set, then this operation failed with a ““ [DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException). Abort this algorithm without taking any further steps.

      3. If index’s is unset, or if index key is not an array key then store a record in index containing index key as its key and key as its value. The record is stored in index’s such that the list is sorted primarily on the records keys, and secondarily on the records values, in ascending order.

      4. If index’s is set and index key is an array key, then for each subkey of the of index key store a record in index containing subkey as its key and key as its value. The records are stored in index’s list of records such that the list is sorted primarily on the records keys, and secondarily on the records values, in order.

        It is valid for there to be no subkeys. In this case no records are added to the index.

        Even if any member of is itself an array key, the member is used directly as the key for the index record. Nested are not flattened or “unpacked” to produce multiple rows; only the outer-most array key is.

    5. Return key.