Consider this snippet.
const nums = [1, 2, 3];
const out = nums.map((n) => { n * 2; });
console.log(out);
Why is the output not [2, 4, 6], and what is the simplest fix.
Ellen
Consider this snippet.
const nums = [1, 2, 3];
const out = nums.map((n) => { n * 2; });
console.log(out);
Why is the output not [2, 4, 6], and what is the simplest fix.
Ellen
map uses the callback’s return value, and with {} your arrow function returns nothing, so you get [undefined, undefined, undefined].
Quelly
:: Copyright KIRUPA 2024 //--