jayykaa
jayykaa

Reputation: 143

why does Object.keys(array) return the indexes as a string, and keys(array) returns them as numbers?

for example:

greetings = ['hey','hi','hello']

Object.keys(greetings) // ["0", "1", "2"]

BUT

keys(greetings) // [0, 1, 2]

Upvotes: 3

Views: 785

Answers (1)

Kelvin Schoofs
Kelvin Schoofs

Reputation: 8718

You are trying the command line API's keys, which isn't actually part of standard JavaScript. It's something Chromium-based browsers inject in DevTools.

As for why it returns different results, not sure. On the other hand, in JavaScript, indexing with a number is identical to indexing with the string version of that number, so it doesn't really matter.

Upvotes: 1

Related Questions