Skip to content

Using map instead of a for loop in ECMAScript 5 JavaScript

Updated: at 02:12 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...

Check out the ORM (Object Relational Mapper) PRISMA. The database access method I use in all my projects