New Javascript ForEach iterator

Have to start getting used to some iterator syntax.  Here’s how we USED to do it:

for (let color in colors) {
            let colorObj = {};

            colorObj.code = colors[color].colorPrdId;
   = colors[color].colorName;
            colorObj.imgSwatch = colors[color].imgSwatch;


Here’s the new way to code the same thing:

        colors.forEach(function (color) {
                code: color.colorPrdId,
                name: color.colorName,
                imgSwatch: color.imgSwatch

More about modern iterators

Leave a comment

Your email address will not be published. Required fields are marked *