Using map instead of a for loop in ECMAScript 5 JavaScript

Posted by Peter Kellner on November 21, 2015 · 1 min read

 

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...