简体   繁体   中英

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]

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM