I just started working on a new project working with TypeScript. I am leaving from another project that also worked with TypeScript. Since native for the loop in TypeScript is available, we decided (the old project team) to use this one. Espacialy was much more convenient for me to write a for loop related to my java background.
Now in the new project, they use the _.foreach () loop everywhere to iterate over arrays.
What I'm wondering is there any performance difference between native TypeScript for and _.foreach ()
I created a small test in jsperf so that the seam is more or less the exact same speed ...
https://jsperf.com/foreach-vs-forof/12
TypeScript For
for (let num: string of list){ console.log(num); }
In javascript
var list = "9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9".split(); //Transpiled TypeScript for of | **19,937 ยฑ5.04% for (var _i = 0, list_1 = list; _i < list_1.length; _i++) { var num = list_1[_i]; console.log("" + num); } //lodash | 20,520 ยฑ1.22% _.forEach(list, function(item) { console.log("" + item) });
Imho, I would prefer the TypeScript native to become more readable to me.
What do you suggest using? Are there any other points to use or better _.forEach