Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Accessing object attributes that are numbers

Hello guys, I'm wondering if is it possible to access a value that is indexed by a number as an atrrib

Following this:

{{ post.title }} {# for $post->title #}
{{ post['title'] }} {# for $post['title'] #}

In my case, "title" is an integer! and is not an array, so I can't do {{ some['42'] }}


edited Feb '18

Having pure numbers as object property names is a bad practice... you should avoid it if you can.

But it's possible, here's a previous thread about this:

Agree with @lajos.. if you really really need to do it just cast to array.

edited Feb '18

Thanks for reply, yes is it a bad practice, but what about if I have not control to the source of the data?

As i remember volt doesn't allow to access like this. Just add filter to volt.