question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

changed each-behaviour for indexed arrays in 2.10

See original GitHub issue

Hey!

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:open
  • Created 7 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
rwjbluecommented, Dec 27, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found