Closed Eswcvlad closed 4 months ago
fromEntries()
wants a very specific structure: an array of arrays where the nested arrays have a key (string) and value (any).
Key in the pair is converted to string somewhat unexpectedly
... Clearly the keys must be converted to string. But you're right that leaving the conversion to JS isn't the best outcome. Should result in:fromEntries([[[1, 2, 3], "val"]]) -> {"[1,2,3]": "val"}
fromEntries([[{a: 1}, "val"]]) -> {"{\"a\": 1}": "val"}
Changed my mind on coercing key values to string. I've opted for a strict interpretation:
Don't think this is very important in practice, since it is mostly just an inverse of
entries
, but for completeness sake...fromEntries(`null`)
throws a TypeError instead of returning an empty object. With the current type coercion rules this is unexpected and might be something to keep in mind.Incomplete array pairs are silently skipped:
fromEntries([["a", `null`], ["b"], `[]`]) -> {"a": null}
. Having an error in such cases, I think, would make sense.On the other hand, having a bigger pair is also silent:
fromEntries([["a", 1, 2]]) -> {"a": 1}
. Not sure, if it makes sense to be strict here, but might be worth-wile to mention, that this is supported.Key in the pair is converted to string somewhat unexpectedly (JS leaking):
fromEntries([[`null`, "value"]]) -> {"null": "value"}
fromEntries([[[1, 2, 3], "val"]]) -> {"1,2,3": "val"}
fromEntries([[{a: 1}, "val"]]) -> {"[object Object]": "val"}