3

for example:

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

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

BUT

keys(greetings) // [0, 1, 2]
7
  • 2
    What is keys()? Commented Jul 30, 2021 at 18:36
  • @VLAZ it seems to be doing the same thing, i tried it on the console... just a function that gives u keys in an object. Commented Jul 30, 2021 at 18:39
  • 1
    Keys will always be a string. Check this question Commented Jul 30, 2021 at 18:39
  • 1
    @jayykaa we prefer to not go by "seems like" but something more actionable. I can give you the reference for Object.keys but not for keys. If it's non-standard, we probably shouldn't be guessing what it does. Commented Jul 30, 2021 at 18:40
  • 1
    Question I have is why would you want to use Object.keys on an array in the first place Commented Jul 30, 2021 at 18:47

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

On FF keys(["a", "b", "c"]) returns [ "0", "1", "2" ]
i dont know enough about this, so if u get votes ill market it as the answer! thanks
For me it returns a number array. Since it isn't actually part of any JS specification, it actually doesn't matter how it behaves. Regular JavaScript (in <script> tags etc) shouldn't be able to even access that function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.