I have an array of number, I want to calculate the square of numbers and display them in list. Right now I am calculating squares separately and rendering them separately using map function as follows
var arr = [1, 2, 3, 4, 5];
for (var i = 0; i < arr.length; i++) {
arr[i] = arr[i] * arr[i];
}
render() {
return html`<ul>
${arr.map(item => html`<li>${item}</li>`)}
</ul>`;
}
Is there a way such that the operations are performed with map function. I am new to using map function.