Следите за новинками
в нашем Telegram канале. Жми, чтобы подписаться:)
⊗jsvuPmLpAK 28 of 72 menu
◀ ▶

Getting keys when iterating over arrays in Vue

Sometimes, in addition to the array elements, we would like to access the keys as well. For this, the following extended syntax is used:

<template> <p v-for="(elem, key) in arr"> {{ key }} {{ elem }} </p> </template>

You can do various operations with keys when outputting. For example, let's make the numbers start with one:

<template> <p v-for="(elem, key) in arr"> {{ key + 1 }} {{ elem }} </p> </template>

The following array is given:

data() { return { arr: ['x', 'y', 'z'], } }

Print the keys of this array as a list ul.

← →
↑
English▼
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline