From 9a5991303944d7cb8a1af9a2d97d3342b4762e0e Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 27 Feb 2017 09:43:40 -0800 Subject: [PATCH] util: avoid using forEach PR-URL: https://github.com/nodejs/node/pull/11582 Reviewed-By: Matteo Collina Reviewed-By: Colin Ihrig --- lib/util.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/util.js b/lib/util.js index 8c880c674b5ad3..3378109b6126ed 100644 --- a/lib/util.js +++ b/lib/util.js @@ -682,12 +682,13 @@ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { if (remaining > 0) { output.push(`... ${remaining} more item${remaining > 1 ? 's' : ''}`); } - keys.forEach(function(key) { + for (var n = 0; n < keys.length; n++) { + var key = keys[n]; if (typeof key === 'symbol' || !key.match(/^\d+$/)) { output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true)); } - }); + } return output; } @@ -718,10 +719,10 @@ function formatSet(ctx, value, recurseTimes, visibleKeys, keys) { var str = formatValue(ctx, v, nextRecurseTimes); output.push(str); }); - keys.forEach(function(key) { + for (var n = 0; n < keys.length; n++) { output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - key, false)); - }); + keys[n], false)); + } return output; } @@ -735,10 +736,10 @@ function formatMap(ctx, value, recurseTimes, visibleKeys, keys) { str += formatValue(ctx, v, nextRecurseTimes); output.push(str); }); - keys.forEach(function(key) { + for (var n = 0; n < keys.length; n++) { output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - key, false)); - }); + keys[n], false)); + } return output; } @@ -768,10 +769,10 @@ function formatPromise(ctx, value, recurseTimes, visibleKeys, keys) { output.push(str); } } - keys.forEach(function(key) { + for (var n = 0; n < keys.length; n++) { output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - key, false)); - }); + keys[n], false)); + } return output; }