DEV Community

Discussion on: Stop using Array.map() everywhere 🥵

 
aminnairi profile image
Amin

Well, if you are going with Array.prototype.reduce, you better be not using any side-effects.

const root = document.getElementById("root");

if (!root) {
  throw new Error("Root not found");
}

const fruits = ["banana", "apple", "pear"];

const innerHTML = fruits.reduce((html, fruit, index) => {
  return `${html}#${index + 1}: ${fruit}<br>`;
}, "");

root.innerHTML = innerHTML;
Enter fullscreen mode Exit fullscreen mode

Some comments have been hidden by the post's author - find out more