Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript loop through array using .map

const loadAll = async function (imgArr) {
  try {
    let singleImage = imgArrItem => createImage(imgArrItem);
    // creates 3 promises
    const imgs = imgArr.map(singleImage);
    console.log(imgs);
  } catch (error) {
    console.log('Images not loaded');
  }
};
loadAll(['img/img-1.jpg', 'img/img-2.jpg', 'img/img-3.jpg']);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #loop #array
ADD COMMENT
Topic
Name
5+7 =