7.3. Convert a key to a value

The steps to convert a key to a value are as follows. These steps take one argument, key, and return an ECMAScript value.

  1. Let type be key’s type.

  2. Let value be key’s value.

  3. Switch on type:

    number

    Return an ECMAScript Number value equal to value

    string

    Return an ECMAScript String value equal to value

    date

    1. Let date be the result of executing the ECMAScript Date constructor with the single argument value.

    2. Assert: date is not an abrupt completion.

    3. Return date.

  1. *binary*
  2. 1. Let len be the length of value.
  3. 2. Let buffer be the result of executing the ECMAScript ArrayBuffer constructor with len.
  4. 3. Assert: buffer is not an [abrupt completion](https://tc39.github.io/ecma262/#sec-completion-record-specification-type).
  5. 4. Set the entries in buffers \[\[ArrayBufferData\]\] internal slot to the entries in value.
  6. 5. Return buffer.
  7. *array*
  8. 1. Let array be the result of executing the ECMAScript Array constructor with no arguments.
  9. 2. Assert: array is not an [abrupt completion](https://tc39.github.io/ecma262/#sec-completion-record-specification-type).
  10. 3. Let len be the length of value.
  11. 4. Let index be 0.
  12. 5. While index is less than len:
  13. 1. Let entry be the result of running the steps to [convert a key to a value](#convert-a-key-to-a-value) with the indexth entry of value as input.
  14. 2. Let status be [CreateDataProperty](https://tc39.github.io/ecma262/#sec-createdataproperty)(array, index, entry).
  15. 3. Assert: status is true.
  16. 4. Increase index by 1.
  17. 6. Return array.