-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 returns incorrect keys for arrays that have gaps #95
Comments
Yes, it definitely should (for certain definitions of undefined). From your example, |
I was a bit lazy in writing out the example (does == perform a good array comparison?? probably not), but console.log( _.keys(myArray)) does give a value of [0,1,2], as keys works (for arrays) by checking the array length, which is always 1+[the array's greatest key], and then uses _.range, which assumes all the keys from 0 to myArray.length-1 exist. |
Oh, sorry, I completely missed line 501 last night. I must have been very tired. I agree, that looks like it could be a problem. I believe line 501 could just be removed to fix it. edit: but I am still unable to reproduce your described behaviour... looking into it |
maybe try |
I see. Since I was using a browser with native |
Yep, the problem is that the |
How would this perform The >=0 returns true for 0, 1, "1", but false for "string" |
Or (bearing in mind that >=0 also returns true for "" (which is a valid object key I think))
|
@wheresrhys: the simple solution mentioned above works fine. Line 501 was an improper attempt at optimizing |
Thanks for researching this, everyone. I've removed the offending false optimization at SHA: 2f369f8. It'll go out with the next release. |
Running the following code:
var myArray = [1, 2, 3];
delete myArray[0];
_.keys(myArray) == [0,1, 2] // true
_.keys(myArray) == [1, 2] // false
Shouldn't _.keys ignore undefined array values?
The text was updated successfully, but these errors were encountered: