changed each-behaviour for indexed arrays in 2.10
See original GitHub issueHey!
I just noticed that Ember 2.10 introduces a changed behaviour when looping over indexed arrays with unset indexes.
Let’s assume this array:
let a = [];
a[5] = 'foo';
a[6] = 'bar';
and this hbs:
{{#each testArray as |v k|}}{{k}},{{/each}}
In 2.9 this produces 5,6
and in 2.10 it produces 0,1,2,3,4,5,6
.
I also made a twiddle for that
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Changed value for an indexed array item leads to duplication ...
To demonstrate that on an example, I chose one migration yml script taken from migrate_plus module (in particular, a simplified form of ...
Read more >php - Change an associative array into an indexed array / get ...
I was wondering if there was either a function or an easy way to change an associative array into an indexed array. To...
Read more >Indexed collections - JavaScript - MDN Web Docs - Mozilla
This chapter introduces collections of data which are ordered by an index value. This includes arrays and array-like constructs such as ...
Read more >PHP Indexed Arrays - W3Schools
PHP Indexed Arrays. There are two ways to create indexed arrays: The index can be assigned automatically (index always starts at 0), like...
Read more >Array Indexing · CodeCraft - JavaScript - BuzzCoder
Access an element. Similar to string, array elements are accessed using square brackets to enclose the index number: arr[i] . Change array element....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The issue here is that (for performance reasons) we are using a standard
for
loop for{{#each
support in 2.10+. Prior versions used.forEach
and that natively support sparse arrays (and that is one of the reasons for some known performance issues).We did it intend to support sparse arrays in prior versions and making changes to 2.10+ to support them would negatively impact performance of all usages of
{{#each
which is not an acceptable trade off for us.We should document the fact that we do not support sparse arrays with
{{#each
in the API docs and add a test (likely a tweak of #14760) that shows the current behavior is intentional.For folks that definitely need this support, I’d recommend using
{{#each-in
as someone else mentioned above.@rwjblue https://github.com/emberjs/ember.js/pull/19147