Hey there, I have a simple query that's giving me some trouble. My goal is to flatten an array with a single layer of depth while also multiplying each element by 2. However, when I attempt to utilize flatMap on arr1, the output in the console displays NaN instead of the expected result: an array containing 5 elements where each one is multiplied by 2. Check out the code snippet below:
const arr1 = [ [2,5] , [5,10,15] ];
const arr2 = arr1.flatMap((el) => el * 2);
console.log(arr2);
Expected // [4, 10, 10, 20, 30]
Actual // [Nan, Nan]
If I run flatMap without the multiplication operation, I successfully retrieve the array with individual elements. It's only upon trying to multiply each value that the NaN issue arises. Can someone help troubleshoot this for me?
const arr3 = arr1.flatMap((el) => el); console.log(arr3);
Actaul // [2,5,5,10,15];