#790 ✓ resolved
Andriy Tyurnikov

each(), _each(), forEach() and for

Reported by Andriy Tyurnikov | September 9th, 2009 @ 02:45 PM | in 1.7

var a = ['a', 'b'];
a[5] = 'c';
var str = '';
a.each(function(item) {
    str += item;
});
alert(str);
//gives 'abc' in Opera/FF/Safari
//and ab**undefinedundefined**c in MSIE

This is example, given by Protoype antagonist:
Problem:
where forEach is present - Prototype using forEach.
If forEach is not present (MSIE) we use for loop(without check of indexes), and getting 'undefined' as a result of attempt to access elements of array with undefined indexes.
So we have inconsistent behavior of each() in different browsers

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The Prototype JavaScript library.

Shared Ticket Bins

Attachments

Referenced by

Pages