diff --git a/lib/handlebars/helpers/each.js b/lib/handlebars/helpers/each.js index 914928d6d..3f8696ccb 100644 --- a/lib/handlebars/helpers/each.js +++ b/lib/handlebars/helpers/each.js @@ -36,7 +36,7 @@ export default function(instance) { if (context && typeof context === 'object') { if (isArray(context)) { for (let j = context.length; i < j; i++) { - if (i in context) { + if (context[i] !== undefined) { execIteration(i, i, i === context.length - 1); } } diff --git a/spec/regressions.js b/spec/regressions.js index 4dc2ac89c..ae0992d44 100644 --- a/spec/regressions.js +++ b/spec/regressions.js @@ -288,4 +288,11 @@ describe('Regressions', function() { shouldCompileTo('{{helpa length="foo"}}', [obj, helpers], 'foo'); }); + + it('GH-1227: Array of undefineds', function() { + var array = [undefined, undefined]; + shouldCompileTo('foo{{#each array}}{{@index}}{{.}}{{/each}}bar', {array: array}, 'foobar'); + var array2 = new Array(2); + shouldCompileTo('foo{{#each array}}{{@index}}{{.}}{{/each}}bar', {array: array2}, 'foobar'); + }); });