Arrays output

Output of a part of the array

In order to make the answer that will be output on the screen correct, you need to remember that:

  • If we output a variable in a variable, we separate their names with dots.
  • If we output a part of the array, we separate it with dots, and put the object number [0]. The numbering starts from zero from the top downwards. After the object number, we write the name of the desired key.

For example, to output value Moscow from the last_request object, you need to call the variable last_request.items.[1].town

Output of each element of the array

Let's say the server response contains an array in last_request object:

{
 "last_request": {
  "items": [
   {
    "town": "Kursk"
   },
   {
    "town": "Moscow" 
   },
   {
    "town": "Belgorod"
   }
  ]
 }
}

To output the elements one by one, you need to write the following template:

{{#each last_request.items}}
{{this.town}}
{{/each}}

At the output, the user will receive:

Kursk
Moscow
Belgorod
To the beginning ↑