Loop on array of objects
See original GitHub issueDescribe the bug Loop on array of objects
To Reproduce
team: {
teammemberName.career: [
{
company: "Company name",
description: "Whatevah here",
}
]
then try to do something like this:
{#each $_(`team.${selectedMember}.career`) as c, i}
<h5>{$_(`team.${selectedMember}.career.${i}.company`)}</h5>
{/each}
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:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top 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 >for...in - JavaScript | MDN - MDN Web Docs
Array indexes are just enumerable properties with integer names and are otherwise identical to general object properties. The for...in 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 >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 FreeTop 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
Top GitHub Comments
Fixed in
3.2.0
🎉I’ve written a custom
getArrayFromLocale
workaround to make this possible.i18next
does this: https://www.i18next.com/translation-function/objects-and-arraysI 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.