# Jekyll Front Matter Array Index access

**URL:** <https://talk.jekyllrb.com/t/jekyll-front-matter-array-index-access/5280>\
**Category:** Help\
**Created:** [November 27, 2020, 6:46am UTC](https://talk.jekyllrb.com/t/jekyll-front-matter-array-index-access/5280 "2020-11-27T06:46:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ROBOTIS-David](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/robotis-david/32/2861_2.png) [@ROBOTIS-David](https://talk.jekyllrb.com/u/ROBOTIS-David)\
**Post date:** [November 27, 2020, 6:46am UTC](https://talk.jekyllrb.com/t/jekyll-front-matter-array-index-access/5280/1 "2020-11-27T06:46:11Z")

</div>

Hi, guys,

Thank you for clicking this ticket,

On Front Matter

```auto
---
layout: archive

lang: en

ref:
- xl430-w250
- xc430-w150
---

```

Mark Down

```auto
{% for sec in page.ref %}

{{ sec }} <-- This works 

{{ sec[0] }} <-- This does not work.. 

{% endfor %}

```

Is there any way to access the index of the particular array?

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)\
**Post date:** [November 27, 2020, 10:38am UTC](https://talk.jekyllrb.com/t/jekyll-front-matter-array-index-access/5280/2 "2020-11-27T10:38:37Z")

</div>

> [@ROBOTIS-David](#):
>
> Is there any way to access the index of the particular array?

When using the Liquid `{% for %}` tag, you have access to the loop index via the `forloop` object.  
The index of the current item iterated can output by `{{ forloop.index }}`  
(_Note: It starts with 1 instead of 0_).

---

<div class="post-metadata">

**Author:** ![ROBOTIS-David](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/robotis-david/32/2861_2.png) [@ROBOTIS-David](https://talk.jekyllrb.com/u/ROBOTIS-David)\
**Post date:** [November 27, 2020, 11:00am UTC](https://talk.jekyllrb.com/t/jekyll-front-matter-array-index-access/5280/3 "2020-11-27T11:00:11Z")

</div>

Hi, Thank you for your advice.

Unfortunately, it does not work…

Front Matter

```auto
layout: archive
ref:
  - ref1: "xl430-w250"
  - ref2: "xc430-w150"
  - ref3: "xh430-w210"

```

Markdown

```auto
{% for reference in page.ref %}

{{ reference.index[1] }} 

{{ reference.index1 }}

{{ reference.index 1 }}

{{ reference.1 }}

{% endfor %}

```

😱

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [November 27, 2020, 1:05pm UTC](https://talk.jekyllrb.com/t/jekyll-front-matter-array-index-access/5280/4 "2020-11-27T13:05:52Z")

</div>

Regarding the first section

```auto
---
layout: archive

lang: en

ref:
- xl430-w250
- xc430-w150
---

```

If you want to use `[0]` index then don’t do it on a for loop.

Here you can get the first element of the array

```auto
{{ page.ref[0] }}

```

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [November 27, 2020, 1:11pm UTC](https://talk.jekyllrb.com/t/jekyll-front-matter-array-index-access/5280/5 "2020-11-27T13:11:57Z")

</div>

Regarding the 2nd case, you defined a list of hashes when I think you just want a hash. Note lack of leading dashes

```auto
ref:
  ref1: "xl430-w250"
  ref2: "xc430-w150"
  ref3: "xh430-w210"

```

Then can do

```auto
{% for r in page.ref %}
- Key {{ r[0] }} - Value {{ r[1] }}
{% endfor %}

```

The zero and one indexes are to unpack the r item…

As your frontmatter will be converted from YAML to a Ruby object stored like this.

```ruby
{ "ref1": "x1430-w250"}

```

And when you use the for loop it becomes an array (or a tuple) of exactly two elements.

```ruby
["ref1", "x1430-w250"]

```

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)\
**Post date:** [November 27, 2020, 2:21pm UTC](https://talk.jekyllrb.com/t/jekyll-front-matter-array-index-access/5280/6 "2020-11-27T14:21:57Z")

</div>

I think you misunderstood my comment.  
I suggested that you use `{{ forloop.index }}` explicitly.

```auto
---
lang: en
ref:
- xl430-w250
- xc430-w150
---

{% for item in page.ref %}
  {{ forloop.index }}. {{ item }}
{% endfor %}

```
