New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_.keys returning always strings #965
Comments
Keys are always strings. var obj = {};
obj[1] = 1;
for (var key in obj) console.log(typeof key); // string You can look up key If you want the keys as numbers, try var obj = {};
obj[1] = 1;
_.map(_.keys(obj), Number); |
Hi @marcalj! Returning property names as strings is part of the spec. If you need numbers, @caseywebdev's solution above will work for most cases. |
Ouch I see, thanks for the quick response! You rock!! Thanks again! |
@caseywebdev solution wont work when you have mixed key objects. such as {"asdf":123, 1:1234} I do realize you said "most" cases, i was just pointing out when it wouldn't work. |
@johnymonster with mixed keys, it can be modified to _.map(_.keys(obj), function (key) { return isNaN(+key) ? key : +key; }); |
_.keys({111: 222, 333: 444})
returns["111", "333"]
, but expected[111, 333]
.Also affects other functions like _.pairs:
_.pairs({1: 1})`returns`[["1", 1]]`, but expected`[[1, 1]]
.Thanks!
The text was updated successfully, but these errors were encountered: