[Vuejs]-Typecasting v-for key Vue

2πŸ‘

βœ…

In JavaScript objects the keys are always strings. It you provide a key that is not a string then its automatically converted to string by javascript. AFAIK it is by design choice .See Object.keys()

You can pass index as your third argumemt like this:

<div class="checkbox" v-for="(value, key, index) in range">

And pass index to your method but as vuejs warns(here):

When iterating over an object, the order is based on the key enumeration order of Object.keys(), which is not guaranteed to be consistent across JavaScript engine implementations.

Its better to cast like this myMethod(Number(key))

πŸ‘€Vamsi Krishna

Leave a comment