Problems with displaying ForLoop

@laoandrei
I asume you want to have all the user-names in a kind of list or even a table or repeater, right?

This part here is the important one…

I have tried to do $w(‘text91’).text = userName; but it only showed the latest result fetched, my guess is because it displayed all of them one by one then stopped at the last one
Yes i see it the same way, the loop stops and you just see the last user-name.

What you will need to have all of them to be shown, is an ARRAY which will collect all the user-names first and then you could push that ARRAY for example to a TABLE or REPEATER.

This would be the structure, how it should look like…

[
  {
    "_id": "1",
    "firstName": "John",
    "lastName": "Doe",
    "image": "http://someImageUrl/john.jpg"
  },
  {
    "_id": "2",
    "firstName": "Jane",
    "lastName": "Doe",
    "image": "http://someImageUrl/jane.jpg"
  }
]

That means…

  1. Generating an ARRAY…
let myArray = [ ]
  1. pushing new Value to the generated new array…
myArray.push({"User": userName})
  1. At the end your new array —> “myArray” looks like that…
[
  {"User": "rob45ca1"},
  {"User": "Owensaurus"},
  {"User": "samlot"},
  {"User": "cole_porter"},
  {"User": "Goldcraft_911"},
]

Now you should be ready to push this data to a table or repeater.

Good luck and happy coding. :wink: