A has an associated type which is one of: number, date, string, binary, or array.

    🚧 Binary keys are new in this edition. They are supported in Chrome 58, Firefox 51, and Safari 10.1. 🚧

    A key also has an associated value, which will be either: an if type is number or date, a if type is string, a list of s if type is binary, or a list of other if type is array.

    An ECMAScript [ECMA-262] value can be converted to a by following the steps to convert a value to a key.

    The following ECMAScript types are valid keys:

    • primitive values, except NaN. This includes Infinity and -Infinity.

    • Date objects, except where the [[DateValue]] internal slot is NaN.

    • primitive values.

    • ArrayBuffer objects (or views on buffers such as ).

    • Array objects, where every item is defined, is itself a valid key, and does not directly or indirectly contain itself. This includes empty arrays. Arrays can contain other arrays.

    Attempting to convert other ECMAScript values to a will fail.

    To compare two keys a and b, run these steps:

    1. Let ta be the type of a.

    2. If ta is array and tb is binary, string, date or number, return 1.

    3. If tb is array and ta is binary, string, date or number, return -1.

    4. If ta is binary and tb is string, date or number, return 1.

    5. If tb is binary and ta is string, date or number, return -1.

    6. If ta is string and tb is date or number, return 1.

    7. If tb is string and ta is date or number, return -1.

    8. If tb is date and ta is number, return -1.

    9. Let va be the of a.

    10. Let vb be the value of b.

    11. Switch on ta:

      number

      date

      1. If va is greater than vb, then return 1.

      2. Return 0.

    The a is greater than the key b if the result of running the steps to with a and b is 1.

    The key a is less than the b if the result of running the steps to compare two keys with a and b is -1.

    The a is equal to the key b if the result of running the steps to with a and b is 0.

    Members of binary keys are compared as unsigned values (in the range [0, 255]) rather than signed values (in the range [-128, 127]).