I'm curious about the .map() function and its usage with arrays.
Typically, we use it like this:
function myFunction(num) {
return num * 2;
}
const numbers = [1, 2, 3, 4];
const newArr = numbers.map((element) => myFunction(element))
However, I came across a code snippet that looks like this:
const resultToRow = (r: MyProductsDto) => ({
rowData: tableColumns.map(() => r),
});
In this particular example, MyProductsDto is an Interface and tableColumns is an Array.
But what does .map(() => r)
do exactly?
r isn't a function but an Interface, so why is the arrow function empty with no arguments?