Nice post! When working with JavaScript/TypeScript, I usually go for the forEach array method, which is pretty convenient for usage with functions:
forEach
const fruit = ['apple', 'banana', 'orange']; fruit.forEach(console.log); // apple // banana // orange
If using a library like lodash, you can also iterate over objects (though iteration order is not guaranteed):
const funcs = { square: x => x ** 2, abs: x => Math.abs(x), reciprocal: x => 1 / x }; _.forEach(funcs, (fn, fnName) => { console.log(`${fnName}(-2) = ${fn(-2)}`); }); // square(-2) = 4 // abs(-2) = 2 // reciprocal(-2) = -0.5
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice post! When working with JavaScript/TypeScript, I usually go for the
forEach
array method, which is pretty convenient for usage with functions:If using a library like lodash, you can also iterate over objects (though iteration order is not guaranteed):