Ali Ghassan
Ali Ghassan

Reputation: 1180

How to get only one element from arrays

l have this data json

{
  "name": "AL_mazyunh",
  "day": [
    20,
    21,
    22
  ],
  "enDayName": [
    "Wednesday",
    "Thursday",
    "Friday"
  ]
}

l want take only one element from those arrays . example enDayName get only Wednesday . l used slice, but he shows only 2 element {{forecast.enDayName| slice:1}}

Upvotes: 0

Views: 604

Answers (1)

jo_va
jo_va

Reputation: 13993

You can simply index the array:

{{ forecast.enDayName[0] }}

or use slice but with both start and end arguments, but this will return a sub-array, so you still need to index the result:

{{ (forecast.enDayName | slice:0:1)[0] }}

Upvotes: 2

Related Questions