I've a for loop which iterates over an array of objects and for each object in the array it returns a method which formats the object.
I was wondering if there's a better substitute for the for loop instead of 'forEach' I've used here. Could you please suggest something?
Here's the code:
for (var index = 0; index < arrItems.length; index++) {
return formatObj(arrItems[index]);
}
forEach substitue:
var formattedObj;
arrItems.forEach(function (item) {
formattedObj = formatObj(item);
});
return formattedObj;
Note: I've this loop running inside an else condition.