Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

forEach returns undefined for arrays begin do not with 0 #8510

Closed
ne3Vubeki opened this issue Aug 6, 2014 · 4 comments
Closed

forEach returns undefined for arrays begin do not with 0 #8510

ne3Vubeki opened this issue Aug 6, 2014 · 4 comments

Comments

@ne3Vubeki
Copy link

Version 1.2.21
If we pass an array:

[
  1: ......
  2: ......
  ..........
]

it forEach returns 'undefined', as cycle is inserted:
for( var i = 0 .....)
Previous versions properly treated such arrays.

@ne3Vubeki ne3Vubeki changed the title forEach returns undefined for arrays begining with 0 forEach returns undefined for arrays begin do not with 0 Aug 6, 2014
@caitp
Copy link
Contributor

caitp commented Aug 6, 2014

it's not super clear what you're saying, could you provide a reproduction?

@petebacondarwin
Copy link
Contributor

@ne3Vubeki - Perhaps you can start by updating this Plunker to show your problem: http://plnkr.co/edit/7B9cARoiM4Ti5DFTwLxA?p=preview

@jeffbcross jeffbcross added this to the Purgatory milestone Aug 6, 2014
@ne3Vubeki
Copy link
Author

In principle, everything is shown:
http://plnkr.co/edit/7B9cARoiM4Ti5DFTwLxA?p=preview
The first in the log is 'undefined'

@caitp
Copy link
Contributor

caitp commented Aug 7, 2014

okay, I see. You're right, this is the behaviour that Array.prototype.forEach would have, so it makes sense for us to do the same thing. I'll submit a patch u_u

caitp added a commit to caitp/angular.js that referenced this issue Aug 7, 2014
…ing properties)

Array.prototype.forEach will not invoke the callback function if the properety is not present in the
object. Because of this, we have the illusion of not iterating over non-added properties in a sparse
array.

From ECMAScript:

9. Repeat while k < len
     a. Let Pk be ToString(k).
     b. Let kPresent be HasProperty(O, Pk).
     c. ReturnIfAbrupt(kPresent).
     d. If kPresent is true, then
            i. Let kValue be Get(O, Pk)
            ... (steps for invoking the function and aborting if it throws)

Closes angular#8510
Closes angular#8522
caitp added a commit to caitp/angular.js that referenced this issue Aug 7, 2014
…ing properties)

Array.prototype.forEach will not invoke the callback function if the properety is not present in the
object. Because of this, we have the illusion of not iterating over non-added properties in a sparse
array.

From ECMAScript:

9. Repeat while k < len
     a. Let Pk be ToString(k).
     b. Let kPresent be HasProperty(O, Pk).
     c. ReturnIfAbrupt(kPresent).
     d. If kPresent is true, then
            i. Let kValue be Get(O, Pk)
            ... (steps for invoking the function and aborting if it throws)

Closes angular#8510
Closes angular#8522
caitp added a commit to caitp/angular.js that referenced this issue Aug 7, 2014
…ing properties)

Array.prototype.forEach will not invoke the callback function if the properety is not present in the
object. Because of this, we have the illusion of not iterating over non-added properties in a sparse
array.

From ECMAScript:

9. Repeat while k < len
     a. Let Pk be ToString(k).
     b. Let kPresent be HasProperty(O, Pk).
     c. ReturnIfAbrupt(kPresent).
     d. If kPresent is true, then
            i. Let kValue be Get(O, Pk)
            ... (steps for invoking the function and aborting if it throws)

Closes angular#8510
Closes angular#8522
@caitp caitp closed this as completed in 3623019 Aug 20, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants