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.

Loop on array of objects

See original GitHub issue

Describe the bug Loop on array of objects

To Reproduce

team: { [
    company: "Company name",
    description: "Whatevah here",

then try to do something like this:

{#each $_(`team.${selectedMember}.career`) as c, i}

of course this won’t work #each $_(`team.${selectedMember}.career`) loops more times than the actual length of career.

by reading the tests i discovered that the lib is flattening the array so it means that this each loop is looping on the strings instead of the array. Is this an expected behavior? what’s the correct way to do this stuff?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

kaisermanncommented, Nov 5, 2020

Fixed in 3.2.0 🎉

micleymancommented, Aug 5, 2020

I’ve written a custom getArrayFromLocale workaround to make this possible.

Also, I don’t have experience with a lot of i18n libraries, do you know any that allow this kind of behavior?

i18next does this:

I don’t have much experience with i18n, but iterating over logical groups makes a lot of sense and it’s the first thing I looked for in the library. I implemented svelte-i18n after I was already iterating over arrays of objects, not doing so feels like regression.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to loop through an array containing objects and access ...
1. Just loop through an array ... const myArray = [{x:100}, {x:200}, {x:300}]; myArray.forEach((element, index, array) => { console.log(element.x); // 100, 200, ...
Read more >
Loop through an array of objects in JavaScript - Techie Delight
Loop through an array of objects in JavaScript · 1. Using Array.prototype.forEach() function · 2. Using for…of statement · 3. Using Object.entries() function...
Read more >
5 Ways Javascript Loop Through Array Of Objects
1. Using for loop ... for loop is the most common way to loop through any iterable in JavaScript. You can also use...
Read more > - JavaScript | MDN - MDN Web Docs
Array indexes are just enumerable properties with integer names and are otherwise identical to general object properties. The loop will ...
Read more >
Looping over arrays and objects in JavaScript - Medium
The forEach array method loops through the array and uses the property names to operate based on each object property.
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 Post

No results found

github_iconTop Related Hashnode Post

No results found