Array.filter: max number of matches?

Brendan Eich brendan at mozilla.org
Tue Nov 13 12:33:00 PST 2012


Andrea Giammarchi wrote:
> wait, I might have misunderstood your problem ... so you want to stop 
> iterating, right ?
>
> When that is the case, you can simply drop the iteration like this:
>
> myArray.slice().filter(function (value, index, original) {
>   // do your stuff
>   if (conditionSatisfied) {
>     original.length = 0;
>   }
> });
>
> there, you can break the iteration as easy as that :-)

Making a copy and then mutating its length seems worse than using some, 
though.

/be



More information about the es-discuss mailing list