Have you ever found yourself in a situation where you have reluctantly rewritten that nice one-line map function just to log your outputs?
const data = ['1', '2', '3'];
const mappedData = data.map((el) => {
console.log(el);
return Number(el);
});
Well, now you don't have to. You see, console.log returns undefined which is perfect for a conditional statement.
const data = ['1', '2', '3'];
const mappedData = data.map((el) => console.log(el) || Number(el));
Thank you for participating in my Tom Blog.
Top comments (0)