Skip to content

Using map instead of a for loop in ECMAScript 5 JavaScript

Updated: at 05:05 PM

 

Before

for (i = 0; i < speakers.length; i++) {
                speakers[i].speakerImageUrl = "https://www.siliconvalley-codecamp.com/attendeeimage/" +
                    speakers[i].id + ".jpg";
            }

After

            speakers.map(function(speaker){
               speaker.speakerImageUrl = "https://www.siliconvalley-codecamp.com/attendeeimage/" +
                    speaker.id + ".jpg";
            });

Just Sayin...