Returns a copy of object with integer numbers as keys instead of whatever it has.
object
keysToNumbers({ '1': true }); // Yields: { 1: true } Copy
keysToNumbers({ '1': true }); // Yields: { 1: true }
The onInvalidKey sets how to handle keys that cannot be converted to integers.
onInvalidKey
keysToNumber({ hello: 'there' }, `ignore`); // Yields: { }keysToNumber({ hello: 'there' }, `throw`); // ExceptionkeysToNumber({ hello: 'there' }, `keep`); // Yields: { hello: 'there' } Copy
keysToNumber({ hello: 'there' }, `ignore`); // Yields: { }keysToNumber({ hello: 'there' }, `throw`); // ExceptionkeysToNumber({ hello: 'there' }, `keep`); // Yields: { hello: 'there' }
Floating-point numbers will be converted to integer by rounding.
keysToNumbers({ '2.4': 'hello' }); // Yields: { 2: 'hello' } Copy
keysToNumbers({ '2.4': 'hello' }); // Yields: { 2: 'hello' }
Returns a copy of
object
with integer numbers as keys instead of whatever it has.The
onInvalidKey
sets how to handle keys that cannot be converted to integers.Floating-point numbers will be converted to integer by rounding.